DRYing up my controllersDRY
Posted 09 June 2014 - 07:54 PM Best Answer
Those two links are the same, of course they look identical
I think you mean the people and the thing controllers, right? Those look pretty similar, but I wouldn't do any DRYing it up on those two. I believe that you need to be able to read the files individually as well, and the only thing to do here would be to create a third controller, that the two first could inherit from.
Posted 09 June 2014 - 11:27 PM
Whoops. Yes I meant the person and thing controllers.
That advice seems reasonable. Readability aside, it would also mean more work! I have other stuff I want to do to get this thing usable. I might still revisit this at a later date after I've learned more.
Posted 10 February 2015 - 06:56 PM
What if you are using transactions in your controller actions? When I delete a Person, I want to log an Activity so I wrap both of those in a transaction:
person.transaction do person.destroy! user.track person, :destroy end
I believe it's a best practice to user the bang! methods in a transaction. But what if an exception is raised like ActiveRecord::RecordNotDestroyed or in my case a custom Person::DeleteLastAdmin < StandardError exception?
Should the controller use a begin..rescue construct like:
begin # do transaction # report success for each format rescue StandardError # report failure for each format end
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users