anonymous-scope

Can I create an *un*named scope in Rails?

蹲街弑〆低调 提交于 2019-12-10 15:39:45
问题 I know you can create named scopes in Rails, which allow you to specify conditions which can then be built on later: named_scope :active, :conditions => {:active => true} ... MyModel.active.find(...) This works by creating a proxy object which isn't evaluated until later on. What I want to know is if it's possible to create a dynamic un named scope? By which I mean, is there a method 'foo' with which I can go scope = MyModel.foo(:conditions => {:target_id => 4}) and then pass scope around as