Rails: Skinny Controller vs. Fat Model, or should I make my Controller Anorexic?

Posted by Nick Gorbikoff on Stack Overflow See other posts from Stack Overflow or by Nick Gorbikoff
Published on 2010-03-31T03:46:13Z Indexed on 2010/03/31 3:53 UTC
Read the original article Hit count: 330

Filed under:
|
|
|

I know similar questions have been answered before - such as: Where should logic go, where to do certain tasks, etc. But I have a more specific question - How far should I take this axiom: "keep your controller skinny, make your model fat!"

Here is an example:

For instance let's say I have multiple source of verification data. A good example would be a VIN number - I can verify it against, manufacturers data source, DMV's data source, also my local databases - to see what I have on record. So I have a model called Vin and vins_controller. Inside the model I have 5 methods: check_against_local_db, check_against_dmv, check_against_car_maker_1, check_against_car_maker_2, etc.

In my controller keeping with the REST, in action show - I have a simple case statement which looks at the params[:source], and based on source specified - will call specific check method.

Now here is the question: Should I leave the logic that governs which data source to call in controller or should I move it to model and then in controller just do something like check_vin(source, vin)?

Should I make my controller anorexic?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about controller