Rails before_filter for specific actions in controller

Create in your ApplicationController method:

def check_privileges!
  redirect_to "https://stackoverflow.com/", 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]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)