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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Sep-13 15:18 UTC
Re: Refactoring controllers with multiple functions per action
On 13 September 2011 15:58, Hans <Hans.Marmolin-6LjvI5LOC4niH4Lt12DN6A@public.gmane.org> wrote:> 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 ?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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
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 ? On 13 Sep, 17:18, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 13 September 2011 15:58, Hans <Hans.Marmo...-6LjvI5LOC4niH4Lt12DN6A@public.gmane.org> wrote: > > > 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 ? > > 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-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Colin Law
2011-Sep-14 13:12 UTC
Re: Re: Refactoring controllers with multiple functions per action
On 14 September 2011 13:40, Hans <Hans.Marmolin-6LjvI5LOC4niH4Lt12DN6A@public.gmane.org> 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> > On 13 Sep, 17:18, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 13 September 2011 15:58, Hans <Hans.Marmo...-6LjvI5LOC4niH4Lt12DN6A@public.gmane.org> wrote: >> >> > 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 ? >> >> 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 > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > >-- gplus.to/clanlaw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.