wha*_*ird 12 ruby postgresql activerecord ruby-on-rails ruby-on-rails-4.2
*更新:现在已修复4.2.stable和4.2.1*
在Rails 4.2.0(和当前的4.2.stable)中,该ensure_in_range方法在AR验证之前发生,产生一个RangeError
如果我做一些简单的事情
@obj.threshold = 10_000_000_000
Run Code Online (Sandbox Code Playgroud)
在具有postgres类型整数的列上
threshold | integer |
Run Code Online (Sandbox Code Playgroud)
它产生了
RangeError:10000000000超出ActiveRecord :: ConnectionAdapters :: PostgreSQL :: OID :: Integer的范围,限制为4来自.../2.0.0-p598/lib/ruby/gems/2.0.0/bundler/gems/rails -62e9e61f2d1b/activerecord/lib/active_record/type/integer.rb:41:在`ensure_in_range'中
这是真的!但告诉用户.有一个ActiveRecord模型验证,如
validates :threshold, presence: true,
numericality: { greater_than_or_equal_to: 0, less_than: 1_000_000}
Run Code Online (Sandbox Code Playgroud)
我无法想象这是预期的行为,任何人都有任何解释为什么这种类型演员在验证之前发生?
获取最新的rails版本来修复此错误,最近由Sean Griffin修复
要在版本发布之前执行此操作,请删除gemfile中的特定版本并使用git location提示:
gem 'rails', :git => 'https://github.com/rails/rails.git'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5290 次 |
| 最近记录: |