0
這讓我瘋狂。我試圖設置設計的專家和一切工作正常,直到我嘗試設置默認角色。在我的情況下,默認角色是用戶。當我嘗試登錄,我得到以下錯誤:評論家整合不能寫未知屬性`角色`
引發ArgumentError在設計:: SessionsController#新
應用程序/模型/ user.rb:26:在`set_default_role」
這裏是我的用戶.RB:
class User < ActiveRecord::Base
enum role: [:user, :gig, :band, :venue, :promoter, :admin]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :user
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
belongs_to :role
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :profile, presence: true,
uniqueness: true,
format: {
with: /[a-zA-Z0-9-]+/,
message: 'Must be formated correctly.'
}
before_create :set_default_role
has_many :gigs
private
def set_default_role
self.role ||= Role.find_by_name('user')
end
def gravatar_url
stripped_email = email.strip
downcased_email = stripped_email.downcase
hash = Digest::MD5.hexdigest(downcased_email)
"http://gravatar.com/avatar/#{hash}"
end
end
這裏是我的rold.rb:
class Role < ActiveRecord::Base
has_many :users
end
什麼想法?