我user has_many websites
在创建新网站时使用与关系相关的设计undefined method has_role? for nil:NilClass
class Website < ActiveRecord::Base
attr_accessible :priority
belongs_to :user
before_create :set_priority
private
def set_priority
if user.has_role? :admin
self.priority = 3
end
end
end