[Rails] Re: Where to put large application controller code
Code that doesn't fit neatly into a model, view or controller, or that
is shared across multiple models, views or controllers, should be
extracted into a module most of the time, and included where it needs to
be. So if you have some controller code like the CSV processing that you
mentioned, it could be a good idea to create a module called something
like "CsvProcessor", extract the functions into it, and include it in
the controllers/models that uses it.
Even if its only used by one model/controller it might still be a good
idea to extract it, to avoid messing up the core functionality of that
model/controller.
> Are you suggesting to put "everything" into a model
Not if it isnt related to a model, that makes no sense. I dont always
keep model related code in the model either. I start out by putting
"everything" into the model, and if/when a model starts to get messy, I
begin extracting things to keep the core concerns to themselfs.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home