0

我在实现ransack gem时遇到了一些困难,我有一个带有索引操作的页面控制器和一个带有索引操作的后控制器。但是,当我在页面控制器的索引操作(pages#index)中执行搜索时,结果会呈现在 post 控制器的索引操作(posts#index)中。这是否意味着我只能从特定资源的视图中搜索,还是我犯了错误?

pages#index 
def index
  @q = Post.search(params[:q])
  @posts = @q.result(distinct: true)
end

pages#index
<%= search_form_for @q do |f| %>
  <div class="field">
    <%= f.label :title_cont %><br>
    <%= f.text_field :title_cont, :class => "input text" %>
  </div>
  <div class="actions">
    <%= f.submit "Search"%>
  </div>
<% end %>
4

1 回答 1

2
<%= search_form_for @q,:url=>pages_path do |f| %>
  <div class="field">
    <%= f.label :title_cont %><br>
    <%= f.text_field :title_cont, :class => "input text" %>
  </div>
  <div class="actions">
    <%= f.submit "Search"%>
  </div>
<% end %>

像这样修改搜索表单中的代码。它现在可以工作了。

于 2013-10-17T09:51:50.180 回答