app/controllers/party.rb
def load_user_and_party(allow_invitees = false)
      @user = load_user_from_session
      begin
        @party = Party.find_by_id!(Integer(params['party_id']))
        # allow owner
        return if @user == @party.user
        # Allow invitees
        return if allow_invitees && @party.invites.any? { |invite| invite.user == @user }
      rescue ArgumentError, ActiveRecord::RecordNotFound
        # Expected error on valid urls, simply 404 below
      end

      # Not allowed
      flash['alert-danger'] = 'Invalid Party'
      redirect to '/', 404
    end
# Load user via session id and party
# Sets @user and @party
# Enforces permissions
Load user via session id and party
Sets @user and @party
Enforces permissions
Load user via session id and party Sets @user and @party Enforces permissions
def load_user_and_party(allow_invitees = false)
      @user = load_user_from_session
      begin
        @party = Party.find_by_id!(Integer(params['party_id']))
        return if @user == @party.user
        return if allow_invitees && @party.invites.any? { |invite| invite.user == @user }
      rescue ArgumentError, ActiveRecord::RecordNotFound
      end
      flash['alert-danger'] = 'Invalid Party'
      redirect to '/', 404
    end
def load_user_and_party ( allow_invitees = false ) @user = load_user_from_session begin @party = Party . find_by_id! ( Integer ( params [ 'party_id' ] ) ) return if @user == @party . user return if allow_invitees && @party . invites . any? { | invite | invite . user == @user } rescue ArgumentError , ActiveRecord :: RecordNotFound end flash [ 'alert-danger' ] = 'Invalid Party' redirect to '/' , 404 end
Load user via session id and party
Sets @user and @party
Enforces permissions
Load user via session id and party Sets @user and @party Enforces permissions
# allow owner # Allow invitees # Expected error on valid urls, simply 404 below # Not allowed
allow_invitees