Skip to content

Instantly share code, notes, and snippets.

@fweep
Created April 4, 2013 00:20
Show Gist options
  • Save fweep/5306664 to your computer and use it in GitHub Desktop.
Save fweep/5306664 to your computer and use it in GitHub Desktop.
before filter example
class StudentsController < ApplicationController
before_filter :find_student, only: [:show, :update]
def show
# @student will already be loaded here
# do whatever
end
private
def find_student
if params[:id] =~ /^w/
@student = Student.find_by_university_id(params[:id])
else
@student = Student.find(params[:id])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment