Hi everyone,
I am having a problem rendering js, this is my code:
in the main view index.html.erb I have
In the partial _poll.html.erb I have:
<%= form_tag(:action => “update_all”, :remote => true) do %>
<% for @poll in @polls %>
<%= fields_for @poll do |f| %>
<%= f.check_box (:selected, “index” => @poll.id) %>
<%= @poll.name %>
<%= @poll.votes %>
<% end %>
<% end %>
<%= submit_tag "Update" %>
<% end %>The method in the controller looks like this:
def update_all
params[:poll].each do |id, attr|
poll = Poll.find(id)
if (attr['selected'] == "1")
poll.votes = poll.votes + 1
poll.save
end
end
respond_to do |format|
format.html { redirect_to(stipso_path) }
format.js
end
end
I have a file called update_all.js.rjs which I think it is supposed to
be called from the controller but it is ignored because html is
processed instead.
I basically want to replace the poll content using AJAX.
Here is the log msg from the rails s console:
Started POST “/foo/update_all?remote=true” for 127.0.0.1 at Wed Jun 08
21:09:13 +0100 2011
Processing by FooController#update_all as HTML
What am I doing wrong?