我在heroku上有一个奇怪的问题,这是我得到的错误:
我正在使用 rails 3.2.8,ruby 1.9.3,具有活跃的管理员,友好的 id!
/app/app/models/user.rb:2:in `<class:User>': uninitialized constant User::FriendlyId (NameError)
在我的本地环境中,也使用 postgres,一切正常......
这是我的用户模型
class User < ActiveRecord::Base
extend FriendlyId
after_initialize :set_username
before_create :set_as_student
friendly_id :username, use: :slugged
ROLES = %w[admin coordinator student]
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
# attr_accessible :title, :body
attr_accessible :email, :password, :password_confirmation, :remember_me,
:name, :code, :phone, :roles
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.inject(0, :+)
end
def roles
ROLES.reject do |r|
((roles_mask || 0) & 2**ROLES.index(r)).zero?
end
end
def role?(role)
roles.include? role.to_s
end
def self.search(query)
where do
((name =~ "%#{query}%") | (code =~ "%#{query}%"))
end
end
def should_generate_new_friendly_id?
new_record?
end
private
def set_username
self.username = self.email.split('@')[0]
end
def set_as_student
self.roles=(['student'])
end
end
我相信它必须与friendly_id 做一些事情,但我不知道出了什么问题,非常感谢您的帮助!
谢谢你们。