Question

I am having a bit off difficulty implementing the ransack gem I have a pages controller with an index action and post controller also with an index action. However when I perform a search in the index action of the pages controller (pages#index) the results are rendered in the index action of the post controller(posts#index). Does this mean i can only search from within the views of a particular resource or am I making a mistake ?

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 %>
Was it helpful?

Solution

<%= 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 %>

Modify the code in the search form like this. It will work now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top