我有两个不同的控制器(scholarships_controller、scholarships_browse_controller)来查看奖学金模型。我希望我的 Ransack 搜索功能在当前页面上显示搜索结果。因此,例如,如果我在 /scholarships_browse 上并使用搜索功能,我希望它使用 Scholarships_browse_controller 并在 /scholarships_browse 上显示结果。
目前,如果我在 /scholarships_browse 上搜索,它会使用 Scholarships_controller 并重定向到 /scholarships 以显示结果(而不是 /scholarships_browse)。
ScholarshipsBrowseController 和 ScholarshipsController 的代码
def index
@search = Scholarship.search(params[:q])
@scholarships = @search.result.page(params[:page]).per(3) #allows 3 scholarships on a page at a time
@search.build_condition
respond_to do |format|
format.html # index.html.erb
format.json { render json: @scholarships }
end
结尾
奖学金浏览 index.html.erb 的代码:
<%= search_form_for @search do |f| %>
<%= f.condition_fields do |c| %>
<div class="field">
<%= c.attribute_fields do |a| %>
<%= a.attribute_select %>
<% end %>
<%= c.predicate_select compounds: false, only: [:cont, :eq, :gt, :lt] %>
<%= c.value_fields do |v| %>
<%= v.text_field :value %>
<% end %>
</div>
<% end %>
<div class="actions"><%= f.submit "Search" %></div>
<% end %>
所以,我想我特别想问当我在 /scholarships_browse 时,如何确保我使用的是 ScholarshipsBrowseController 索引而不是 ScholarshipsController 索引?