I’ve been working on this problem for over 3 days. :=[
I am trying to pick up the values that are being passed from a jQuery. My code for the view,
application.js and controller is as follows.
view:
<%= form_tag update_result_answers_path, :remote => true do %>
<% @answers.each do |q| %>
<%= q[0].question %>
<% [ 1, 2, 3, 4, 5 ].each do |f| %>
<%= radio_button_tag q[1].id, f, f == q[1].score, :class => 'submittable' %>
<% end %>
<% end %>
<% end %>
application.js:
$('.submittable').live
('change', function()
{
$(this).parents('form:first').submit();
return false;
}
);
controller:
def update_result
@answ = Answer.where(id = name)
@answ.update_attributes params[:score]
end
In the console window where the rails server is running i get the following when a radio button is clicked:
Parameters: {"authenticity_token"=>..., "155"=>"2"}
I named the radio button set with the id of the answer record (see q[1].id in the view). So the name of the radio button set, which is also the id of the answer record, is “155”. The answer is “2”. Params[:id] doesn’t capture the id so i changed to “@answ = Answer.where(id = name)” in the controller and get the following error:
"undefined local variable or method `name'"
How do i change the controller to grab the name of the radio button set and the value?
Thanks.
I’d suggest another level of nesting – so that you can segregate your Answers from other form parameters coming in.
I’m not very well versed with Rails view helpers and my solution might be slightly 2.3-ish.