RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
gem "meta_where" gem "meta_search"
Product.where(:price.lt => 5) Product.where({:price.lt => 5} | {:name.matches => "%video%"}) Product.order(:released_at.desc) MetaWhere.operator_overload! Product.where(:price < 5)
def index @search = Product.search(params[:search]) @products = @search.all end
<%= form_for @search do |f| %> <p> <%= f.label :name_contains %> <%= f.text_field :name_contains %> </p> <p> <%= f.label :price_gte, "Price ranges from" %> <%= f.text_field :price_gte, :size => 8 %> <%= f.label :price_lte, "to" %> <%= f.text_field :price_lte, :size => 8 %> </p> <p class="button"><%= f.submit "Search" %></p> <% end %> <p> Sort by: <%= sort_link @search, :name %> | <%= sort_link @search, :price %> | <%= sort_link @search, :released_at %> </p>