Where to put code?

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


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs