0
我有rails_best_practices
寶石和我得到以下警告:Ruby on Rails的使用模特協會
APP/app/controllers/users_controller.rb - use model association (for @user_answer)
參考這個要點的代碼:
begin
@user_answer = @user.user_answers.where(:question_id => @question_id).first
if @user_answer
@user_answer.answer_id = @answer_id
@user_answer.save!
@message = 'Answer updated successfully!'
else
@user.user_answers.create(:question_id => params[:questionId], :answer_id => params[:answerId])
@message = 'Answer submitted successfully!'
end
rescue ex
@message = ex.message.split(':')[1].chomp
end
但根據page on model association它看起來不像是違反了這一點,它看起來像是正確的。我是否錯過了這件事?
哪一行是第33行?我認爲這是抱怨「@ user_answer.answer_id = @answer_id」,它看起來像在你分享的鏈接中解釋的氣味類似 –
哎呦我刪除了指向代碼所在的方法的行號(所以行號實際上並沒有幫助解決這個問題) – acconrad