开发者

Use named_scopes from a model, with another model

Is there any way to reuse named scopes defin开发者_JAVA技巧ed in a model, in another model.

I have some generic named_scopes defined that do some filtering, and I would like to use them in another model.Copying them to the new model seems a bit to non-dry.

PS: I'm using Rails 2.3.8


Sure, just write them into a file that you put in the lib directory and include them in each of the models. That way the named scopes will be included in each of the models you include them within.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜