Non-Functional Use of Named Scope
# Model
class Searchable
cattr_accessor :conditions
named_scope :filtered, lambda{{:conditions => conditions}}
end
# Controller
def index
if params[:conditions]
Searchable.conditions = params[:conditions]
@searchables = Searchable.filtered
else
@searchables = Searchable.all
end
end
# View
<% for searchable in @searchables %>
<%= Searchable.content %>
<% end %>
<%= link_to "Show only cool items", :action => :index, :conditions => ['cool= ?',true] %>
Original snippet written by Kevin Gisi
Last updated at 20:32 PM on Aug 08, 2008