Skip to content

Instantly share code, notes, and snippets.

@agraves
Created May 29, 2012 21:05
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 agraves/2830708 to your computer and use it in GitHub Desktop.
Save agraves/2830708 to your computer and use it in GitHub Desktop.
Controller with & without before filters
# 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