Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 自定义ActsAgoCodables错误消息_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 自定义ActsAgoCodables错误消息

Ruby on rails 自定义ActsAgoCodables错误消息,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我在Rails 3应用程序的模型中有以下代码。问题是这些错误消息没有出现在我的表单中。我知道错误消息是正确的,因为其他字段的其他错误正在显示。我做错了什么 validates_as_geocodable :allow_nil => true do |geocode| if geocode.nil? model_instance.errors.add_to_base("Please specify a location") return false end

我在Rails 3应用程序的模型中有以下代码。问题是这些错误消息没有出现在我的表单中。我知道错误消息是正确的,因为其他字段的其他错误正在显示。我做错了什么

validates_as_geocodable :allow_nil => true do |geocode|

  if geocode.nil?
    model_instance.errors.add_to_base("Please specify a location")
    return false 
  end

  if geocode.precision >= :locality         
    model_instance.errors.add_to_base("Try to be more specific w/ your location")
    return false 
  end

end
如果你看你会发现

if !geocode ||
    (options[:precision] && geocode.precision < options[:precision]) ||
    (block_given? && yield(geocode) == false)
  model.errors.add :base, options[:message]
end
if!地理编码||
(选项[:精度]&&geocode.precision<选项[:精度])||
(给定区块和产量(地理代码)=假)
model.errors.add:base,选项[:message]
终止
如果
geocode.nil?
那么
yield(geocode)
将永远不会被调用=>您的块也不会被调用。我不知道第二个条件,但我想你也应该检查一下