【问题标题】:Validates greater than existing column in rails model验证大于 rails 模型中的现有列
【发布时间】:2015-12-07 12:54:03
【问题描述】:

我想在更新时验证 :budget_price 始终大于此列中存在的先前值。

我通过 html5 在客户端进行检查,但我如何在 model.rb 中验证它

我写

validates :budget_price, :numericality => { :greater_than => :budget_price }, :on => :update

但它不能正常工作

【问题讨论】:

    标签: ruby-on-rails validation activerecord


    【解决方案1】:

    将你的第二个 :budget_price 更改为 :budget_price_was 喜欢

    validates :budget_price, :numericality => { :greater_than => :budget_price_was }, :on => :update
    

    关于其他方法,另见http://api.rubyonrails.org/classes/ActiveModel/Dirty.html

    【讨论】:

      猜你喜欢
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多