【发布时间】:2014-06-13 01:37:54
【问题描述】:
我不知道这个警告是什么?请提出一些建议。 下面给出的是我的应用程序代码的一部分。 它给了我关于 validates_date 行的声明错误。
Rails 建议我执行以下操作:
class MyValidator < ActiveModel::Validator
def initialize(options={})
super
options[:class].send :attr_accessor, :custom_attribute
end
end
这是下面的应用程序代码:
class Patient < ActiveRecord::Base
searchkick index_name: "patients",text_start: [:first_name,:last_name]
after_update :reindex
has_secure_password
has_many :addresses
has_many :vitals
has_attached_file :avatar, :styles => { :medium => "150x150>", :thumb => "50x50>" }, :default_url => "app/assets/images/missing.png"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
validates :email, email_format: {message: "Invalid email format" }
validates_uniqueness_of :email
validates :password_digest, presence: true, confirmation: true, length: {minimum: 8,message:"Must be of atleast 8 characters"}
validates :first_name, presence: true, format: { with: /\A[a-zA-Z]+\z/, message: "First Name should contain only alphabets"}
validates :last_name, presence: true, format: { with: /\A[a-zA-Z]+\z/, message: "Last Name should contain only alphabets" }
validates_date :dob,:before => lambda { Date.current }, presence: true
validates :password_digest, presence: true, confirmation: true, length: {minimum: 8,message:"Must be of atleast 8 characters"}
validates :primary_phone_no, presence: true,numericality: {only_integer: true}
end
【问题讨论】:
-
请不要投反对票 我需要有关此问题的帮助,该问题刚从 4.1 升级,现在出现此错误。
-
我认为您的意思是您刚刚升级了 到 刚刚发布的 4.1。这只是对最终将在 4.2 中消失的代码的警告。
-
是的,很抱歉上面的错误评论从 4.0.4 升级到 4.1
标签: ruby ruby-on-rails-4