我有rails_best_practices
宝石,我收到以下警告:
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
但是根据关于模型关联的页面,它看起来并没有违反这一点,看起来它正在正确地遵循。我错过了什么吗?