Hi all, what you used to do when your controller function gets lengthy sometimes ? a way i found is just split the function. What is the real and Rails way to keep my code cleaner and maintainable. Thanks, Lekha. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0690101d176f4c932ca3757eb630cdb6%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Use a service object. Google "Service Object Rails" for more. -- Dheeraj Kumar On Monday, 2 December 2013 at 11:46 am, lekha p. wrote:> Hi all, > what you used to do when your controller function gets lengthy > sometimes ? > a way i found is just split the function. What is the real and Rails way > to keep my code cleaner and maintainable. > Thanks, > Lekha. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0690101d176f4c932ca3757eb630cdb6%40ruby-forum.com. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/B22450590A164B469D428770A2DE2DF1%40gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On 2 December 2013 06:16, lekha p. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all, > what you used to do when your controller function gets lengthy > sometimes ? > a way i found is just split the function. What is the real and Rails way > to keep my code cleaner and maintainable.Probably some of the logic should be removed from the controller and put into methods in the model(s). So for example look at the code and anywhere you have a few lines that are to do with extracting data from the model and manipulating it in some way then consider writing a model method that implements that function. You can also extract bits of code into private methods of the controller, but concentrate first on moving stuff into the models. Finally, if there is a lot of code interpreting data encoded in the url then maybe the routes could be improved. Post one of the methods that you want to re-factor if you need some pointers. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv2TxY6L%2BZzZUJ_dZ2vAWF-eyeAMcNYLLDMETa44C953A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
As we say in rails skinny controllers, fat models. Ideally most of the business logic, all database interactions should go to model, becz model is meant to do it. controller methods should only contain request and response code, so that it is easy to test. Regards On Monday, 2 December 2013 11:46:43 UTC+5:30, Ruby-Forum.com User wrote:> > Hi all, > what you used to do when your controller function gets lengthy > sometimes ? > a way i found is just split the function. What is the real and Rails way > to keep my code cleaner and maintainable. > Thanks, > Lekha. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d0daedc2-710d-4e0b-b4e2-e9e99678b54b%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Hi all, Thank you. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1fb422e5d3a74238d44475c2544fbb81%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.