【问题标题】:DEPRECATION WARNING: The `Validator#setup` instance method is deprecated and will be removed on Rails 4.2弃用警告:`Validator#setup` 实例方法已弃用,将在 Rails 4.2 上删除
【发布时间】: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


【解决方案1】:

您现在不必担心。我从validates_date 看到您正在使用validates_timeliness gem - 这是当前正在抛出弃用警告的 g​​em。

这是该 gem 的一个未解决问题,并且正在处理中 - 这是当前未解决的问题:https://github.com/adzap/validates_timeliness/pull/114

我建议您等到他们修复它然后更新 gem。这只是一个警告,现在不会停止任何工作。

【讨论】:

猜你喜欢
  • 2017-08-02
  • 2017-03-08
  • 2017-05-25
  • 2016-12-07
  • 2015-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多