Colin Law wrote in post #1069267:
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.