Eric Gross
2006-Jul-29 23:05 UTC
[Rails] newbie - best place to put methods used in controllers?
Hey guys, Where is the best place to put methods called in your controller? I ask because my controller file is getting bulky with code that doesnt need to be called directly. I was wondering if I could put it in the application.rb or if there is some way to put it in the helper? -- Posted via http://www.ruby-forum.com/.
Daniel N
2006-Jul-30 16:40 UTC
[Rails] newbie - best place to put methods used in controllers?
On 7/30/06, Eric Gross <tennisbum2002@hotmail.com> wrote:> > Hey guys, > > Where is the best place to put methods called in your controller? I ask > because my controller file is getting bulky with code that doesnt need > to be called directly. > > I was wondering if I could put it in the application.rb or if there is > some way to put it in the helper? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >The code that is not called directly may be better placed into a module in your lib directory. The actions that get called on the controller as an action should certainly go into the controller in 99.99% of situations. You can put code into the application helper, but this is generally for views. IMHO this is simply put as: If a method is data integrity related, try and put it in the model. If a method only exists to support the flow of the controller logic, put it in a controller. If a method is there to assist with displaying content, stick it in a view. With any/all of these, modules are always available. It''s a bit hard to know what advice to give with such a small ammount of information. Hope that helps -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060730/76ee1ac5/attachment.html