Created
November 13, 2010 16:57
-
-
Save skanev/675479 to your computer and use it in GitHub Desktop.
A curious piece of Code from http://blog.davidchelimsky.net/wp-content/uploads/2010/11/duplication.pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is the
before_filterbad? And why?