Last active
May 1, 2017 21:54
-
-
Save carlweis/5d24f31fa20aef1626cd9ace2a15c57d to your computer and use it in GitHub Desktop.
Ghosting as a user
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
# config/routes.rb | |
resource :ghost, only: [:create, :destroy] | |
# app/controllers/ghosts_controller.rb | |
class GhostsController < ApplicationController | |
def create | |
session[:admin_id] = current_user.id | |
user = User.find(params[:user_id]) | |
sign_in user | |
redirect_to root_path, notice: "Now Ghosting as #{user.email}" | |
end | |
def destroy | |
sign_in User.find(session[:admin_id]) | |
session.delete(:admin_id) | |
redirect_to admin_path, notice: "Stopped Ghosting" | |
end | |
end | |
# app/controllers/application_controller.rb | |
def ghosting? | |
session[:admin_id].present? | |
end | |
helper_method :ghosting? | |
# app/views/layouts/_header_links.html.erb | |
<%= render "shared/ghosting_link" if ghosting? %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment