Problem rendering rjs

Hi everyone,

I am having a problem rendering js, this is my code:

in the main view index.html.erb I have

<%= render(:partial => 'poll')%>

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?

I think your form is not setting remote correctly.

If it was submitting correctly you should not see ?remote=true.

form tag takes 2 parameters url_for_options and options. If you don’t
put the {} around the first set of options it will assume they are all
url_for_options

form_tag(url_for_options = {}, options = {}, *parameters_for_url,
&block)

Basically I think you need to change your form tag to look like this

<%= form_tag({:action => “update_all”}, :remote => true) do %>

It works! Thanks! stupid brackets… :slight_smile: