Adding condition filter to find records

I think you might be wanting with_scope

Product.with_scope(:conditions => ["id < ?", 10]) do
  stime = Time.now.utc.strfime("%Y-%m-%d")
  @items = Product.find(:all, :conditions => ["publish = 1 and
(publish_from is null or publish_from <= ?) and (publish_to is null or
publish_to >= ?)", stime, stime])
end

all queries within the block automatically have the defined
conditions, ie, they have been scoped.

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000892
http://habtm.com/articles/2006/02/22/nested-with_scope

Chris

take a look at the second link i listed. scan down the page until you
get to the section titled 'around filter'. study the example he has
provided as it sounds exactly like what you are trying to accomplish.

Chris

just put the ScopedAccess class in your models directory.

what i might do in this case is:

class FrontEndController < ApplicationController
end

class MyRealFrontEndController < FrontEndController
end

class MyOtherRealFrontEndController < FrontEndController
end

and put your frontend code in the FrontEndController class

did you take a look at the plugin he wrote? probably much easier than
writing it all yourself.

ruby script/plugin install
http://wota.jp/svn/rails/plugins/branches/stable/scoped_access/