I'm working with Ruby on Rails, trying to get my search bar to display the results, but whenever I had pagination to the products index page I'll have the following error:
My search form:
<div class="navbar-form navbar-right search-form" role="search">
<div class="input-group add-on">
<%= form_with(url: products_path, method: 'get', local: true) do |form| %>
<%= form.text_field :q, id: 'q', class:"form-control", placeholder: "Search ...", value: params[:q] %>
<div class="input-group-btn">
<%= form.submit 'Go', class:"btn btn-default", id:"btn-search"%>
</div><!-- input-group-btn -->
<% end %>
</div>
</div>
In my Views I have:
<div class="text-center">
<%= will_paginate @products, inner_window: 1, outter_window: 0 %>
</div>
My Products controller:
def index
if params[:q]
search_term = params[:q]
@products = Product.search(search_term)
else
@products = Product.all.paginate(page: params[:page], per_page: 6)
end
end
My Products model:
def self.search(search_term)
if Rails.env.production?
Product.where("name ilike ?", "%#{search_term}%")
else
Product.where("name LIKE ?", "%#{search_term}%")
end
end
any help would be greatly appreciated! Thanks!