开发者

Best way to chain methods together in Ruby on Rails

I have written a bunch of methods (around 10 in total) in a rails application. Individually they do only one thing but i will need to chain them together in different ways depending on when is used. Each method returns the same type of data they are just co开发者_StackOverflow社区mputed differently. What is the best way to do that?

To be more precise. I have a module that have all the individual methods in. When I run a rake task I need to chain these methods up differently then being in the controller.

Is there a recommendation way or I should write them differently?

Thanks


If they are finders to retrieve data from models then make them scopes then you can chain them together however you wish. You can even write scopes that chain other scopes together.

You can even nest scopes through class methods

There is a great Railscast on how to do this here - http://railscasts.com/episodes/215-advanced-queries-in-rails-3

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜