如何在路由中的rails应用程序内限制特定MountableEngine的访问

时间:2012-10-31 20:10:58

标签: ruby-on-rails devise authorization cancan

我想仅为具有admin作为角色的用户授予对/ samurai(可安装引擎)的访问权限:

我该怎么做?

我的路线

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 =即时通讯使用CanCan和Devise


更新了

我是Ruby的新手,我用这种方式解决了我的问题!

1)在config / initializers处创建文件;

2)在该文件中我已将该代码放在下面;

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
这有多糟糕?

0 个答案:

没有答案