Created
April 30, 2012 18:12
-
-
Save jamiew/2560572 to your computer and use it in GitHub Desktop.
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 ThingsController < ApplicationController | |
before_filter :get_thing!, :only => [:show] | |
before_filter :friends_only!, :only => [:show] | |
def show | |
render @thing | |
end | |
protected | |
# I'd just call this "get_thing" if it used find_by_{id,login} | |
# or other methods which don't raise exceptions | |
def get_thing! | |
@thing = Thing.find(params[:id]) | |
end | |
def friends_only! | |
if current_user && @user && current_user.friends_with?(@user) | |
# OK | |
# do nothing | |
else | |
# Fail | |
render :text => "not friends", :status => 403 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment