我正在关注 railscasts rails ajax 教程并遇到了一些麻烦,我是否遗漏了什么,或者该教程仅适用于 pre rails 3.1?
控制器:
def index
@notes = Note.search(params[:search])
end
模型:
class Note < ActiveRecord::Base
def self.search(search)
if search
where('name LIKE ?', "%#{search}%")
else
scoped
end
end
end
看法:
<%= 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 %>
咖啡脚本文件:
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
)
错误在这一行:
ActionView::MissingTemplate in Notes#index
<div id="notes"><%= render 'notes' %></div>