只是试图安装 Rolify 以创建一个有权编辑某些具体属性的管理员角色......
我一步一步地遵循它的文档,一切看起来都很好,除了当我尝试向用户添加角色时,它会说
undefined method add_role for <User:0x00000109c39880>
在我的用户模型中,我有rolify
应该给出方法的add_role
方法......
2 重要说明:
我正在使用 friendly_id 我正在使用 devise gem
任何人都可以帮忙吗?
用户模型
class User < ActiveRecord::Base
rolify
attr_accessor :tos_agreement
is_impressionable :counter_cache => true, :column_name => :impressions_counter, :unique => :request_hash
has_many :photos
has_many :tags, through: :photos
has_many :comments, through: :photos
validates :tos_agreement, acceptance: true
extend FriendlyId
friendly_id :name, use: :slugged
mount_uploader :avatar, AvatarUploader
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
def update_with_password(params={})
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
update_attributes(params)
end
# Omniauth Devise
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
@user = user
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
# if user.save
# UserMailer.welcome_email(@user).deliver
# end
end
end
end
end
角色.rb
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
scopify
end
谢谢