I’m following the railscasts rails ajax tutorial and geting into some trouble, am i missing something or is the tutorial only meant to be covered for pre rails 3.1?
controller:
def index
@notes = Note.search(params[:search])
end
Model:
class Note < ActiveRecord::Base
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
end
View:
<%= form_tag notes_path, :method => 'get', :id => "notes_search" do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<div id="notes"><%= render 'notes' %></div>
<% end %>
Coffescript file:
jQuery ->
# Ajax sorting and pagination on click
$('#notes td.sortable a, #notes .pagination a').live('click', ->
$.getScript(this.href)
false
)
# Ajax search on submit
$('#notes_search').submit( ->
$.get(this.action, $(this).serialize(), null, 'script')
false
)
# Ajax search on keyup
$('#products_search input').keyup( ->
$.get($("#notes_search").attr("action"), $("#notes_search").serialize(), null, 'script')
false
)
Error is on this line:
ActionView::MissingTemplate in Notes#index
<div id="notes"><%= render 'notes' %></div>
The
ActionView::MissingTemplateexception basically says that there is no view file for the action you’re trying to render.You need to have a partial view called “_notes.html.erb” for it to work. Inside the view you should have something like that:
I took that code from the tutorial you’re referring to http://railscasts.com/episodes/240-search-sort-paginate-with-ajax, maybe you don’t have those params or don’t have will_paginate gem installed yet, adjust it to your needs.