How to update rails Variable in Javascript

You should use observe_field with what you are trying to accomplish.

<%= radio_button :nominees, :count %>
<%= observe_field(:nominees_count, :on=>'click', :frequency=>0.25,
:update => :vote_count, :with => :nominees_count, :url => { :action =>
:nominees_count_them}) %>
<div id="vote_count"></div>

Then put the method in your controller:

def nominees_count_them
  # add your counts here
  vote_count = (perform a find on the model for the current vote count)
  vote_count += 1
  # Do something with your vote count like update to a table
end

The div id is only there so you can view if it's working. Just look
through observe_field and checkbox and radio buttons. You'll find what
you need to get it working.

This may or may not work for you. I'm just going by what I remember. I
believe the syntax is correct though.

Thanks for the quick reply Alpha,
Actually what i want is while selecting the radio button the vote_count
should be increased.
i have tried thst with update_attribute and increment methods. but the
vote_count is not increased .
could you give some advice about how to increase the vote_count based on
the selection.

Alpha Blue wrote: