我是 Rails 的新手。我正在使用 rolify gem 来添加用户角色。当我尝试从 rails 控制台添加角色时,我遇到了这个问题。有没有人遇到过这个问题?
u = User.first
u.add_role(:admin).save!
错误列表 ===
ActiveRecord::RecordInvalid: Validation failed: Resource type is not included in the list.
rolify 迁移文件 =============
class RolifyCreateRoles < ActiveRecord::Migration
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.timestamps
end
create_table(:users_roles, :id => false) do |t|
t.references :user
t.references :role
end
add_index(:roles, :name)
add_index(:roles, [ :name, :resource_type, :resource_id ])
add_index(:users_roles, [ :user_id, :role_id ])
end
end`
我已按照从此处安装 rolify 的文档 == https://github.com/RolifyCommunity/rolify