This post originated from an RSS feed registered with Ruby Buzz
by Obie Fernandez.
Original Post: RejectConf (at Railsconf 2007) and Unit of Work
Feed Title: Obie On Rails (Has It Been 9 Years Already?)
Feed URL: http://jroller.com/obie/feed/entries/rss
Feed Description: Obie Fernandez talks about life as a technologist, mostly as ramblings about software development and consulting. Nowadays it's pretty much all about Ruby and Ruby on Rails.
Rejectconf did not disappoint, delivering the inside scoop on the really advanced and cutting-edge Rails stuff. I presented my upcoming unit of work concept, which lets you write your controller methods the following way:
classIterationController< ActionController::BaseincludeRenaissance::UnitOfWorkdefcreatecase unit_of_work do
@iteration = Iteration.new(params[:iteration])
endwhenSuccessredirect_to iteration_path(@iteration)
whenValidationErrorrender:action => 'new'endenddefupdatecase unit_of_work do
@iteration = Iteration.find(params[:id])
@iteration.update_attributes(params[:iteration])
endwhenSuccessredirect_to iteration_path(@iteration) andreturnwhenStaleObject
flash[:error] = "Another user beat you to changes"@iteration.refresh_and_apply(params[:iteration])
endrender:action => 'edit'endend
Feedback and comments from folks familiar with the unit of work pattern requested.