Colin Law wrote in post #1069267: > On 18 July 2012 21:00, masta Blasta <li...@ruby-forum.com> wrote: >> >> The code i'm dealing with in particular has a lot of error checking. If >> this & this then fail. If this but not that then fail, and so forth. Of >> course every conditional has various error messages that must be sent >> back to client and else clauses and blah blah. >> >> It would be interesting to have some kind of callback system, that >> monitors different stages of the #create workflow for example, and when >> an error is encountered it bombs out, finds the correct message to >> display and returns to view. > > The first thing to do is to move most of the logic out into the > models. Ideally there should be no business logic in the controllers. > > Colin
This is not so much logic as validation. Many, many validations involving multiple models and associations. So if this association parameter is set to this, than this other association param must be set to either this or this otherwise throw error. What you end up with in the end is 100+ lines of if/else statements That's what makes breaking it up difficult. If I did break things up to other methods or lambdas, i would have these 4-5 line chunks of code that have almost no meaning on their own. Plus since at any point in time I'm juggling 4-5 models, all these would have to be passed around as parameters if some of this logic were to move into ModelClass validations. My one idea so far is to go ahead and break everything into little methods of 4-5 lines and put these in a Module. Then include the module in my controller. then do something like: methodsModule.public_instance_methods.each do |methodName| errors = methodsModule.send methodName, args if errors ...display error ...db:rollback break end end it would not make the code any shorter, but at least somewhat more manageable. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.