Adding condition filter to find records

I think you might be wanting with_scope

Product.with_scope(:conditions => ["id < ?", 10]) do
  stime ="%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])

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


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.


just put the ScopedAccess class in your models directory.

what i might do in this case is:

class FrontEndController < ApplicationController

class MyRealFrontEndController < FrontEndController

class MyOtherRealFrontEndController < FrontEndController

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