나는 단순한 레일로 인해 내 마음을 잃을 것입니다 어디 쿼리. 10 선 전과 같이 작동하는 이유를 이해할 수 없으며 그 후에는 이해하지 못합니다. 나는에 성공적으로 JSON 요청을 할 때 문제레일스 : Where 절이 어떤 조건에서도 작동하지 않습니다
@userID = Token.where(:tokenCode => @tokenReceived)
#@[email protected]+"1" #randomize algorithm required!
@[email protected]=generate_activation_code()
if @userID.nil?
@newToken=Token.new
@[email protected]
else
@tokenToAdd = "12"
@newToken=Token.where(:userID => "1")
#if @newToken.nil?
@newToken.tokenCode="12"
#end
end
#@newToken.save
@init.save
의 원인이 될 수있는 것을 알아낼 수 '에 http : // localhost를 : 3000/inits.json'이하는 오류하지만 톤으로 나에게 페이지를 제공합니다 그 중 주요 오류가 있다고 생각하십시오 :
<h1>
NoMethodError
in InitsController#create
</h1>
<pre>undefined method `tokenCode=' for #<ActiveRecord::Relation:0x007fc43cb40b88></pre>
어떤 이유가있을 수 있습니까? where 절을 모두 잘못 쓰고 있습니까?
편집 : if 절을 활성화하면 작동합니다. 나는 단순히 @newToken 객체가 null이라고 믿는다. 그러나 왜 내가 그 이유를 발견하는 것은 거의 불가능하다. 이 사용자 ID 1.
엄청난 답변을 해주셔서 감사합니다! 니가 내 목숨을 구했어. – Ali