After reading up on a few experiences, I feel this issue might need to be brought up again. Coding in Rails3, I\'m trying to implement some smooth Ajax effects when a user
Watch a Railscast
<%= form_tag products_path, :method => 'get', :id => ↵
"products_search" do %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
and in Js
// Search form.
$('#products_search').submit(function () {
$.get(this.action, $(this).serialize(), null, 'script');
return false;
});
});
When my layout was coded in Haml (application.haml), AJAX wouldn't fire and the work-around code kelly.dunn mentioned didn't work.
respond_to do |format|
format.js {render :layout=>false}
end
The easiest fix was to convert the application layout to .html.erb format.
I found the answer! The issue was that when the controller was rendering the view, it was including the overall layout of my application; the layout was yielding to the rendering action, so my javascript code contained inside of my .js.erb file was spit out into my application.rhtml. I fixed this issue by including this inside of my controller action to display my posts:
respond_to do |format|
format.js {render :layout=>false}
end