Skip to content

Instantly share code, notes, and snippets.

@skanev
Created November 13, 2010 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skanev/675479 to your computer and use it in GitHub Desktop.
Save skanev/675479 to your computer and use it in GitHub Desktop.
class WidgetsController < ApplicationController
before_filter :assign_widget, :only => [:show, :new, :edit, :create:, :update, :destroy]
def show; end
def new; end
def edit; end
def create
if @widget.save
redirect_to(@widget, :notice => 'Widget was successfully created.')
else
render :action => "new"
end
end
def update
if @widget.update_attributes(params[:widget])
redirect_to(@widget, :notice => 'Widget was successfully updated.')
else
render :action => "edit"
end
end
def destroy
@widget.destroy redirect_to(widgets_url)
end
private
def assign_widget
@widget = params[:id] ? Widget.find(params[:id]) : Widget.new(params[:widget])
end
end
@skanev
Copy link
Author

skanev commented Nov 13, 2010

Is the before_filter bad? And why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment