ruby on rails - How to implement Ransack gem -


i'm trying have search form @ header of every web page search through names of "products"

i tried implement ransack gem, not getting products filtered results. through below code, fetches products in database , displays. want display searched products.

# routes.rb resources :product   collection     match 'search' => 'products#search', via: [:get, :post], as: :search   end end  # application.controller.rb before_filter :set_global_search_variable def set_global_search_variable   @q = product.search(params[:q])   @product_search = @q.result end  # application.html.erb <% search_form_for(@q, url: /search, method: :get)  |f| %>   <%= f.label :name %>   <%= f.text_field :name %>   <%= f.submit %> <% end %>  # search_index.erb <% @product_search.each |product| %>   <%= image_tag product.image_url %>     <%= product.name %>   <% end %> <% end %> 

view code

= search_form_for @product_searcher || product.ransack, url: main_app.admin_products_path |f| 

controller code

def index   params[:q] ||= { }   @product_searcher = product.ransack(params[:q])   @products = @product_searcher.result end 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -