所以我正在为我的用户更新验证验证器。但是,由于某种原因,它们的一部分在制作新用户时会影响#create部分。因此禁止用户创建他们的个人资料。
with_options on: :update do |update|
update.validates :about, :city, :why_join, :individuality, presence:true
update.validates :about, length: { in: 20..150 }
update.validates :why_join, :individuality, length: { in: 20..500 }
update.validates :country, length: { in: 4..40}
update.before_save :format_url
update.validates_format_of :city, :country, :with => /\A[a-zA-Z ]+(\d+)?\z/
update.validates_format_of :url_linkedin, :url_twitter, :url_facebook, :with => /\Ahttps?:\/\/[^\n]+\z/i
update.before_save {
self.name = name.strip.titleize
self.city = city.strip.titleize
self.country = country.strip.titleize
}
def format_url
self.url_linkedin = "http://#{self.url_linkedin}" unless self.url_linkedin[/https?/]
self.url_facebook = "http://#{self.url_facebook}" unless self.url_facebook[/https?/]
self.url_twitter = "http://#{self.url_twitter}" unless self.url_twitter[/https?/]
end
end
它返回undefined_method []和def format_url的update.before_save。我不明白为什么......
当我尝试注册新用户时会发生这种情况。