Last active
October 7, 2016 16:17
-
-
Save telagraphic/5474668 to your computer and use it in GitHub Desktop.
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
before_filter :correct_user, only: :show | |
def correct_user | |
@account = Account.find_by_id(params[:id]) | |
redirect_to root_url unless correct_user?(@account.user_id) | |
end |
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
LifeUlator::Application.routes.draw do | |
root :to => "users#new" | |
resources :sessions, only: [:new, :create, :destroy] | |
resources :users | |
resources :accounts | |
match '/signin', to: "sessions#new" | |
match '/signout', to: "sessions#destroy" | |
end |
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
module SessionsHelper | |
def current_user | |
@current_user ||= User.find(session[:user_id]) if session[:user_id] | |
end | |
def registered_user | |
unless current_user | |
redirect_to root_url | |
end | |
end | |
def correct_user?(user) | |
user == current_user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment