rails - AJAX Search,Sort,Paginate with Ransack和Kaminari

时间:2017-02-12 07:00:54

标签: ruby-on-rails ruby ajax ruby-on-rails-4 ransack

我一直在关注本教程https://techbrownbags.wordpress.com/2014/01/17/rails-ajax-search-sort-paginate-with-ransack-kaminari/并且效果很好,问题是在搜索字段时发出以下错误:

Started GET "/catbancos?utf8=%E2%9C%93&q%5BClave_cont%5D=qqq&q%5BDescripcion_cont%5D=&commit=Search" for 127.0.0.1 at 2017-02-12 02:23:59 -0400
Processing by CatbancosController#index as JS
  Parameters: {"utf8"=>"✓", "q"=>{"Clave_cont"=>"qqq", "Descripcion_cont"=>""}, "commit"=>"Search"}
Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)

RuntimeError (No table named catbancos exists.):
  app/controllers/catbancos_controller.rb:8:in `index'

该表被称为" catbancos"而单数是" catbanco"

这是我的控制器索引:

 def index
    @search = Catbanco.search(search_params)
    @search.sorts = 'Clave' if @search.sorts.empty?
    @catbanco = @search.result().page(params[:page])
  end

这是我的index.html.erb

  <% provide(:title, Catbanco.model_name.human.pluralize) %>
  <h1><%= Catbanco.model_name.human.pluralize %></h1>
  <div class="row">
    <%= link_to t("basic.create.type", type: Catbanco.model_name.human ), new_catbanco_path, class: "btn btn-success pull-right" %>
  </div>

  <div id="catbancos"><%= render 'catbancos' %></div>

这是我的部分猫科:

<table class="table table-striped table-bordered table-condensed table-hover">
<thead>

  <%= search_form_for @search, :remote=>"true", url: catbancos_path, :method => :get do |f| %>
      <tr>
        <th class="component_name_header_col">
          <%= sort_link @search, :Clave, "Clave","catbanco", {}, { :remote => true, :method => :get } %>
        </th>
        <th class="component_component_definition_name_header_col">
          <%= sort_link @search, :Descripcion,"Descripcion","catbanco", {}, { :remote => true, :method => :get } %>
        </th>

        <th class="action_col"><%= t("basic.action") %></th>
      </tr>
      <tr>
        <th><%= f.text_field :Clave_cont %></th>
        <th><%= f.text_field :Descripcion_cont %></th>
        <th>  <%= f.submit "Search" %></th>
  </tr>

</thead>
<tbody>
  <% @catbanco.each do |catbanco| %>
<tr>
<td class="component_name_body_col"><%= catbanco.try(:Clave) %></td>
<td class="component_component_definition_body_col"><%= catbanco.try(:Descripcion) %></td>
<td>
<div class="btn-group"><a class="btn dropdown-toggle btn-primary action-btn" href="#" data-toggle="dropdown">
 <%= t('basic.action') %>

 </a>
<ul class="dropdown-menu">
    <li><%= link_to t('basic.show.simple'), catbanco %></li>
    <li><%= link_to t('basic.edit.simple'), edit_catbanco_path(catbanco) %></li>
    <li><%= link_to t('basic.destroy.simple'), catbanco, method: :delete, data: { confirm: 'Are you sure?' } %></li>
</ul>
</div>
<!-- button group --></td>
</tr><% end %>
</tbody>
</table>
<%= paginate @catbanco %>
<% end %>

0 个答案:

没有答案