hey guys,
I am having an issue with AJAX on rails 3. I don't know if it's a bug or something but definitely weird. Basically i have {model,controller,view} that work perfectly over http.
I have an index action in my "articles" controller that searches for a search query supplied from the form on the index view.
the weird behavior: 1. using firebug, i can see that the AJAX request is sent to rails and the response i get is the content of the file index.js.erb! and obviously nothing changes on the page..
rails console log shows that the template index.js.erb was rendered successfully and all is OK (200).
my application layout has: [code] <head> <title>Blog</title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> </head> [/code]
i.e. all prototype is loaded
my index action: [code] def index
if params[:search] @articles = Article.search params[:search] else @articles = Article.all end respond_to do |format| format.html # index.html.erb format.xml { render :xml => @articles } format.js end end [/code]
my index.erb.html [code] <%= form_tag articles_path, :method => :get, :remote => true do %> <%= text_field_tag :search %> <%= submit_tag :search %> <% end %>
<div id="listing"> <%= render :partial => 'list' , :locals => { :articles => @articles } %> </div> <%= link_to 'New Article', new_article_path %> [/code]
my index.js.erb has: [code] page.replace_html 'listing', partial => 'list', :locals => { :articles => @articles } [/code]
the content of the js.erb template is what is returned in the response! why is this happening???
2. the second weird behavior: if I change the JS template file from .js.erb to .rjs, rails renders the http template file!!! even though it received and AJAX request (as evident in firebug), that's really weird..
Please shed some light on why all of this is happening and how do i get it my partial to replace the 'listing' div html.