Rails 3.2.x remote=>true still reloads a page
ajax, ruby-on-rails
Solution
Why did you put there 2 lines?
format.js { render :layout => false } # see note 2
format.js { render :nothing => true }
Remove the second one!
Replace:
<%= link_to "commit", :action => "commit", :remote => true %>
with:
<%= link_to "commit", commit_path, :remote => true %>
The same with the form:
Make your:
<%= form_tag( :action => "commit", :remote => true, :method => :post) do %>
as:
<%= form_tag(commit_path, :remote => true) do %>
Note: `POST` is the default behavior, you can omit it from `form_tag`.
Problem
I've been searching all over and can't figure out why this isn't working. I'm trying to test a very basic ajax action. Here are my code: Controller: ``` def commit respond_to do |format| format.html { redirect_to :action => "index" } # see note 1 format.js { render :layout => false } # see note 2 format.js { render :nothing => true } end end ``` View: ``` <%= link_to "commit", :action => "commit", :remote => true %> <%= form_tag( :action => "commit", :remote => true, :method => :post) do %> <%= submit_tag "commit" %> <% end %> <div id='message'></div> ``` commit.js.erb ``` console.log('committed'); $('#message').html("committed"); ``` The problem is I'd get to the commit method, but the page would reload, which defeats the point of remote=>true Also the commit.js never seemed to get called. Note 1: If I exclude this line, I get the blank page to /commit. Including it makes the page just reload Note 2: I've tried both of these approaches suggested by other SO posts Note 3: I've tried both using link_to and form_tag Can anyone help? Thanks!