0

When a radio button is checked, the whole form is submitted. The answers_controller (below) does update the result, so everything works, but i get the aforementioned error in the console. I realize that in my update_result.js.erb (below) nothing is assigned to the @answers variable but i have been unable to make adjustments to it for the way i am passing the values.

answers_controller:

  def update_result
    params[:answer].each_pair do |key,value|
      @ans = Answer.find(key.to_i)
      @ans.update_attributes(:score => value)
    end
  end

update_result.js.erb:

$("#answers").html("<%=escape_javascript(render(@answers)) %>");

Thanks!

1 Answer 1

1

Change the action like this:

def update_result
  @answers = []

  params[:answer].each_pair do |key,value|
    ans = Answer.find(key.to_i)        
    ans.update_attributes(:score => value)
    @answers << ans
  end
end

Change the update_result.js.erb like this:

$("#answers").html("#{escape_javascript(render(@answers))}");
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for giving it a shot. It still gets the same error. I am pretty sure it is because no value is assigned to @answers.
Can you post full error message that you get? Instead of render(@answers) I think you should do something like render :partial => 'partial_name' (that will output html with @answers data)
i commented out my prior code in the update_result.js.erb file. When i removed it completely, your solution worked perfectly. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.