Rails before_filter for specific actions in controller

后端 未结 1 1714
离开以前
离开以前 2020-12-29 03:33
  def new
    before_filter  do 
      redirect_to \"/\" unless current_admin || current_company
      flash[:notice] = \'You dont have enough permissions to be here         


        
1条回答
  •  青春惊慌失措
    2020-12-29 04:33

    Create in your ApplicationController method:

    def check_privileges!
      redirect_to "/", notice: 'You dont have enough permissions to be here' unless current_admin || current_company
    end
    

    And then in your controller:

    before_filter :check_privileges!, only: [:new, :create, :edit, :save]
    

    Or

    before_filter :check_privileges!, except: [:index, :show]
    

    0 讨论(0)
提交回复
热议问题