我正在使用devise_invitable
gem 在我的应用程序中启用邀请以及为 rails 3 应用程序设计。我有一个User
&Profile
模型。在User
中,有一role
列给出了用户的类型。
现在,我想将创建新邀请的功能限制在管理员范围内,方法是将这个范围界定路线限定到devise/invitations#new
whereuser.role=='admin'
并向所有人开放其余路线。像这样的东西
MyApp::Application.routes.draw do
devise_for :users, skip: [:registrations, :invitations]
as :user do
get 'users/edit' => 'devise/registrations#edit', as: 'edit_user_registration'
put 'users' => 'devise/registrations#update', as: 'user_registration'
# manually define alll devise_invitable routes, except devise/invitations#new
# accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit
# user_invitation POST /users/invitation(.:format) devise/invitations#create
# also the #accept route goes here
end
resource :profile, except: :destroy
authenticated :user, lambda {|u| u.role == "admin"} do
resources :user, controller: "user"
#only allow admin to invite other users
# new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new
end
root to: 'profiles#show'
end
可能的?另外,做同样事情的更好方法是什么?