Created
May 29, 2012 21:05
-
-
Save agraves/2830708 to your computer and use it in GitHub Desktop.
Controller with & without before filters
This file contains 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
# With before filter | |
class FoosController < ApplicationController | |
before_filter :find_foo, :only => [:edit, :show, :update] | |
def create | |
end | |
def edit | |
end | |
def index | |
@foos = Foo.all | |
end | |
def new | |
@foo = Foo.new | |
end | |
def show | |
end | |
def update | |
@foo.update_attributes(params[:foo]) | |
end | |
private | |
def find_foo | |
@foo = Foo.find(params[:id]) | |
end | |
end | |
# Without before filter | |
class FoosController < ApplicationController | |
def create | |
end | |
def edit | |
@foo = Foo.find(params[:id]) | |
end | |
def index | |
@foos = Foo.all | |
end | |
def new | |
@foo = Foo.new | |
end | |
def show | |
@foo = Foo.find(params[:id]) | |
end | |
def update | |
@foo = Foo.find(params[:id]) | |
@foo.update_attributes(params[:foo]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment