I have the following form in a rails app which is not working:
<% form_remote_for :team do |f| %>
<tr>
<% 1.upto(12) do |i| %>
<td>
<%= f.check_box @mo[i] %>
<%= observe_field 'team_' + @mo[i],
:method => :put,
:with => "$(@mo[i] + '=') + $('team_'+@mo[i]).value" %>
</td>
<% end %>
</tr>
<% end %>
@mo[i] is the name of the field in the database (e.g. jan, feb, mar,… dcm). The code would look like this if i were to write them all out:
<% form_remote_for :team do |f| %>
<tr>
<td>
<%= f.check_box :jan %>
<%= observe_field 'team_jan',
:method => :put,
:with => "'jan=' + $('team_jan').value"
</td>
...
</tr>
<% end %>
Thanks for your help.
Your :with statements has some syntax problems, and you are also not interpolating your ruby variables correctly. Try this:
I derived this by taking your intended output
'jan=' + $('team_jan').valueand replacing all instances ofjanwith#{@mo[i]}, which is the way to interpolate your variable that contains the month name.Also, you probably need to add a
:urloption to tell where your ajax call should be sent. Something like this:I am guessing here that your desired endpoint is
team_path(@team), but replace it if it is not.