I managed to create a series of three buttons on the index page, allowing the user to identify a subset of objects in the database - button 1 - type = "new", button 2 - type = "used", button 3 - there are no restrictions, that is, it can be new or be used.
Currently index.html.erb contains:
<%= link_to "New", :controller => params[:controller], :action => params[:action], :product_type => 'New' %>
<%= link_to "Used", :controller => params[:controller], :action => params[:action], :product_type => 'Used' %>
<%= link_to "Don't Restrict", :controller => params[:controller], :action => params[:action], :product_type => nil %>
In the product.rb file, I have:
scope :by_product_type, lambda{|product_type| where(:product_type => product_type) unless product_type.nil? }
Finally, I have productfinder_controller:
before_filter :load_grips, :only => [:index, :bybrand, :bycolour, :byprice]
protected
def load_products
if params[:product_type]
@productssmatchingtype = Product.by_product_type(params[:product_type])
else
@productsmatchingtype = Product
end
end
The above code works exactly as I hoped, by first loading all the elements and restricting them if button 1 or button 2 is pressed.
3 Productfindercontroller, : byprice, bybrand bycolour. , .html.erb, , ...
EXCEPT. , , .. , . , -, ? /, @productsmatchingtype ( productfinder_controller) , ?