· 1 min read
Screencast: MetaSearch und MetaWhere
Download:
Download(16 MB, 8:28) Alternativer Download für iPod & Apple TV(14.4 MB, 8:28)
Resourcen:
Quellcode:
[ruby] # Gemfile gem “meta_where” gem “meta_search”
# rails console 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)
# products_controller.rb def index @search = Product.search(params[:search]) @products = @search.all end [/ruby]
[html] <%= form_for @search do |f| %>
<%= f.label :name_contains %> <%= f.text_field :name_contains %>
<%= 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 %>
<% end %>Sort by: <%= sort\_link @search, :name %> | <%= sort\_link @search, :price %> | <%= sort\_link @search, :released\_at %>
\[/html\]