Question

I have the basic clearance setup -

rails generate clearance:install

and

rails generate clearance:views

In my admin_controller, I have

before_filter :authorize

This makes sure the user is logged in. How would I setup 'admin' privileges on my users and make sure the user has the privlege before allowing them into the admin controller?

Is there a better solution for this?

Thanks!

Andrew

OTHER TIPS

i had the same question, but cancan seems too much for me (small project)

Actually the source code of authorize is quite simple, so my approach here:

open the Clearance::Authorization module in initializer, and add custom methods there:

# config/initializers/clearance_authorization.rb

module Clearance
  module Authorization
    extend ActiveSupport::Concern

    def authorize_admin
      unless(signed_in? && current_user.admin?)
        deny_access
      end
    end
  end
end

don't forget to restart the server :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top