を反復しながら、私は以下のコードを実行するときのparamsを通じてエラーのparams
を反復処理しようとすると、私はエラーを取得する:
def create_score
@quiz = Test.find_by(password: session[:test_password])
@points = 0
@quiz.tasks.each_with_index do |task, index|
@task = Task.find_by(id: task)
@points += @task.score if @task.correct_answers.to_s == send("params[:test][:task#{index}]")
end
@score = Score.new(user_id: 2, name: "Test1", points: @points)
if @score.save
redirect_to root_url
else
redirect_to signup_path
end
end
私が手:
でundefined method `params[:test][:task0]' ...
を
@points += @task.score if @task.correct_answers.to_s == send("params[:test][:task#{index}]")
これは、
{"utf8"=>"✓",
"authenticity_token"=>"8h7rtv2yWio11DFo6kBKutdZl7RDBBaTrt7e8qel8fR5R5XsoXRhRrBeDQPPoZeuBlZ7N5PmqCxik06Z/gQLZQ==",
"test"=>{"task0"=>["4"], "task1"=>["0"], "task2"=>["10"]},
"commit"=>"Zakończ test",
"locale"=>"pl"}
がparams[:test][:task0]
ですが、まだそれがエラーを発生させ、何らかの理由で、私は本当に理由を知らないことを意味します
パラメータは次のようになりsend
方法の問題。これがどうして起こるのか?
文字列の補間が記号 – Deep
@Deepで直接動作しないことに言及すると、それは動作します: ':"タスク#{index} "'。 – ndn