我有一个带有设计的应用程序。我安装了 role_model 和 cancan gem。我将 user.rb 更新为:
require 'rubygems'
require 'role_model'
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :roles, :roles_mask
include RoleModel
roles_attribute :roles_mask
roles :admin, :contributor, :guest
end
然后,在rails控制台中我尝试
> u = User.find(:first)
User Load (1.2ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: ...
> u.roles = [:admin]
NoMethodError: undefined method `roles_mask=' for #<User:0x00000002b57500>
from /home/xxx/.rvm/gems/ruby-1.9.3-p194@rails-3.2.11/gems/activemodel-3.2.11/lib/active_model/attribute_methods.rb:407:in `method_missing'
角色掩码从何而来?我需要包含其他内容吗?