我不知道这个警告是什么?请建议一些东西。 下面给出的是我的应用程序代码的一部分。 它给了我关于 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
最佳答案
您现在无需担心。我从 validates_date
中看到您正在使用 validates_timeiness
gem - 正是该 gem 当前引发了弃用警告。
这是该 gem 上的一个悬而未决的问题,正在处理中 - 这是当前的悬而未决的问题: https://github.com/adzap/validates_timeliness/pull/114
我建议你等到他们修复它,然后更新 gem。这只是一个警告,目前不会停止任何工作。
关于ruby - 弃用警告 : The `Validator#setup` instance method is deprecated and will be removed on Rails 4. 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23325307/