Forum: Ruby on Rails Where to put code?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
988e49987971369d4903c02b3269c8b2?d=identicon&s=25 athem (Guest)
on 2007-01-19 20:27
I have a set of methods that use AR objects to query the database and
use the results, in combination with the application of some simple
business rules (e.g., if-else statements + return values), to compute
values for display in a view.

My question is, generally, where is the appropriate place to put such
code (not in the view!)?

(1) The view-specific helper
(2) The model
(3) The controller

E3640176765dae2465d33ef6eb114691?d=identicon&s=25 Bala Paranj (Guest)
on 2007-01-19 21:27
(Received via mailing list)
If it is very view specific, you can put them in a view helper.

If these methods are needed in almost all the controllers then you can
them in a superclass. Otherwise put them in a helper module and mix it
the controllers that requires it. Think about your application
and use your judgement. Instead of speculating, you could refactor it

I would also separate the business rule logic code from the data
manipulation code. This will allow code reuse.
This topic is locked and can not be replied to.