Refactoring controllers with multiple functions per action

I have controllers with multiple fucntions per action depending on
that they are called from different forms and views.
For example a controller shows a place on a map, but depending on if
the place is selected from a meny or from an autocomplete field or
from some associated model that belongs to place etc I end up with a
fat show action with many cases that is controlled by a :mode flag
I would like to refactor that fat controller to a skinny one,
Should I divide the show action into many different actions, but the
controller will then be as fat as before ?
Should I create a new controller, but then I have two controllers that
shows places on a map, and that seems not very DRY ?
Is there any other solution ?

Appriciate any advices !

Hans

On 13 September 2011 15:58, Hans [email protected] wrote:

shows places on a map, and that seems not very DRY ?
Is there any other solution ?

Thin and fat are relative terms of course. There is no problem with a
certain amount of logic in an action provided it is just determining
what to do next based on information passed to it. If the logic
becomes too complex then that is what may benefit from re-factoring in
some way.

Colin

On 14 September 2011 13:40, Hans [email protected] wrote:

Please don’t top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in the previous message.
Thanks

Thanks for the answere
What is too complex logic ?
I have e.g an action with 4 cases each of about 10 rows concerned with
transforming and testing params values and computing view variables
before rendering the view
Is that good rails practice ?

Difficult to say without seeing the code. Can you move any of the
code into the models? Possibly have some model methods that take the
parameter values and return appropriate data for display.

Colin

I would like to refactor that fat controller to a skinny one,
some way.

Colin


You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


gplus.to/clanlaw

Thanks for the answere
What is too complex logic ?
I have e.g an action with 4 cases each of about 10 rows concerned with
transforming and testing params values and computing view variables
before rendering the view
Is that good rails practice ?