Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
class DryAsFuckController < ActionController::Base %w{index show new edit create update destroy}.each do |action| before_filter "before_#{action}", :only => action end def index; end def show; end def new; end def edit; end def create; end def update; end def destroy; end protected def before_index find_and_assign_single(Fuck) end def before_show find_and_assign(Fuck, params[:id]) end def before_new initialize_and_assign(Fuck) end def before_edit find_and_assign(Fuck, params[:id]) end def before_create initialize_and_assign(Fuck, params[:fuck]).save ? go_to_fuck : render :action => "new" end def before_update find_and_assign(Fuck, params[:id]).update_attributes(params[:fuck]) ? go_to_fuck : render :action => "edit" end def before_destroy find_and_assign(Fuck, params[:id]).destroy redirect_to(fucks_url) end private def find_and_assign_all(klass) instance_variable_set("@#{klass.name.tableize}", klass.find(:all)) end def find_and_assign(klass, id) instance_variable_set("@#{klass.name.underscore}", klass.find(id)) end def initialize_and_assign(klass, attributes = nil) instance_variable_sest("@#{klass.name.underscore}", klass.new(attributes)) end def go_to_fuck redirect_to(@fuck) end end
This paste will be private.
From the Design Piracy series on my blog: