1

I have tried using the 'ransack' search with my application, it works as long as it is in the index view of the controller, it does not work when I try putting the same code in partials. The partial has the header with a search field in it

My index action of expert controller looks like this:

def index
@search = Expert.search(params[:q])
@experts = @search.result
end

The code I have used in the index view of expert is

<form class="navbar-form navbar-left" role="search">                                        
<%= search_form_for @search do |f|  %>
  <div class="form-group">
      <div class="field">
                <%=f.text_field:Location_or_Description_or_Industry_or_Current_Organization_or_Current_Position_cont, :class => "form-control" %>
      </div>
  </div>
  <%= f.submit "Search" , :class => "btn btn-default icon-search"  %> 
<% end %>
</form> 

I am trying to use this code in partial so that I can search from any given page in my app. The error I get when I do so is

ArgumentError in Praclycore#index

Showing c:/repos/pracly/app/views/layouts/_header.html.erb where line #24 raised:
No Ransack::Search object was provided to search_form_for!

<li class="home"><%= link_to image_tag("/img/home.png"), root_path, :class=>"home" %></li>

<form class="navbar- form navbar-left" role="search">                                   
    <%= search_form_for @search do |f|  %>
    <div class="form-group">
    <div class="field">
    <%= f.text_field :Location_or_Description_or_Industry_or_Current_Organization_or_Current_Position_cont, :class => "form-control" %>




Trace of template inclusion: app/views/layouts/application.html.erb

Rails.root: c:/repos/pracly

I am new to ruby on rails, it would be highly appreciated if someone can tell me how can I use ransack with partials and what additional code I need to supply for this to work .

Diceman
  • 20
  • 1
  • 5
samikb
  • 25
  • 5

1 Answers1

0

The @search instance variable is not available in any context other than Expert#search - you will need to setup that variable (or better yet, use the decent_exposure gem) and either expose it at the ApplicationController level or create it in a before filter.

prater
  • 2,330
  • 1
  • 17
  • 15