0

我正在关注 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>
4

2 回答 2

1

ActionView::MissingTemplate异常基本上表示您尝试呈现的操作没有视图文件。

您需要有一个名为“_notes.html.erb”的局部视图才能工作。在视图内部,您应该有类似的内容:

<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<%= will_paginate @notes %>

我从您所指的教程中获取了该代码http://railscasts.com/episodes/240-search-sort-paginate-with-ajax,也许您没有这些参数或没有安装 will_paginate gem但是,请根据您的需要进行调整。

于 2012-06-06T05:51:49.537 回答
1

This totally irrelevant to the tutorial but why don't you consider using datatables. Does the same thing as the railscasts tutorial and also has full documentation and API to make it fully customizable.

于 2012-06-06T08:13:37.027 回答