i want to grant access to /samurai (mountable engine) only for users that have admin as role:
how can i do that?
my routes
authenticate do
mount Resque::Server.new, :at => "/resque"
mount Samurai::Engine => "/samurai"
scope "/admin" do
resources :customers, :images,:categories, :groups,:redirects, :projects, :specs, :indices,:glossaries, :invoices, :users, :products
resources :comments do
member do
post 'approve'
post 'moderate'
post 'disapprove'
end
end
end
P.S = im using CanCan and Devise
Updated
i'm really new in Ruby, i've solved my problem this way!
1) creating a file at config/initializers;
2) in that file i 've put that code below;
Samurai::ApplicationController.class_eval do
before_filter :restrict_access
private
def restrict_access
user = current_user
head :unauthorized unless user.role_id == 1
end
end
how bad its that?