0
已經有similar question已經回答,但由於它不包含新的CanCan 2.0版本,因此似乎已經過時了一些。我需要防止用戶更新某些字段(本例中爲:active
和:limited
),並且只能由管理員編輯。Cancan 2.0,如何限制用戶更新用戶模型中的某些屬性
# ability.rb
if user.persisted?
cannot :update, :users, [:active, :limited]
elsif user.admin?
can :access, :all
end
但是,這段代碼並不妨礙用戶編輯這些字段。
我還在路線上添加了enable_authorization
到一個新的class RegistrationsController < Devise::RegistrationsController
和devise_for :users, path: 'users', controller: 'registrations'
,但這似乎並沒有成功。
不要工作。 – Martin