Commit b2a7ec46 by Tran Hoang Viet

VieTH: Fix authorise admin

parent f8bcc373
class Admin::ApplicationController < ApplicationController
before_action :authenticate_admin!
private
def authenticate_admin!
redirect_to root_path, alert: 'You are not permission.' unless current_user.try(:admin?)
end
end
class Admin::OrdersController < ApplicationController
class Admin::OrdersController < Admin::ApplicationController
before_action :set_order, only: [:show, :update]
before_action -> { authorize(@order) }, only: [:show, :update]
def index
@orders = Order.all.includes(:user).order(created_at: :desc).page(params[:page])
......
class OrdersController < ApplicationController
before_action :authenticate_user!
before_action :set_order, only: [:show, :update]
before_action -> { authorize(@order) }, only: [:show, :update]
before_action -> { authorize(@order) }, only: [:show]
def index
@orders = current_user.orders.includes(:user).order(created_at: :desc).page(params[:page])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment