When I am writing a Rails application it starts out simple with a few if @something.save lines that are pretty self explanatory. Then the application grows and starts to become hairy. Take my contrived example with a grain of salt as I can’t show you production code that I am using.
# app/controllers/widgets_controller.rb class WidgetsController < ApplicationController # # Other methods go here # def something # Maybe we handle the update in a special way widget = Widget.find(params[:id]) widget.some_method(params[:widget]) # for the sake of simplicity let's change the owner foobar = widget.foobar foobar.owner = current_user respond_to do |format| if widget.save if foobar.save format.html { redirect_to widgets_path, :notice => 'Huzzah!' } else widget.some_special_rollback format.html { redirect_to widgets_path, :notice => "You're a moron" } end else format.html { redirect_to widgets_path, :notice => "Not even close"} end end end end What did we learn here? Terribly contrived examples can prove anything, No! Though I liked how easy it was to come up with it but that is not why I wrote the code above. I have seen applications get to that point and when I see it now I start to shake my fist violently at the computer and wonder just what in the world were they thinking.
...