2012-10-09 40 views
0

可能重复:
Paperclip not displaying the error message回形针不显示任何错误消息

我使用Rails 3.2.6。我在我的模型文件中添加了这个:

has_one :avatar, :as => :imageable, :dependent => :destroy 
validates_presence_of :avatar, :message => "can't be empty" 

但如果字段保留blank.I我只在我的页面的顶部越来越Please review the problems below:我没有收到任何错误消息。任何人都可以提出建议

我也试过:

validates :avatar, :presence => {:message => 'Please select the image'} 

回答

0

的:化身字段是不是一个真正的现场。请在avatar_id支票,这是真正的数据库字段:

validates :avatar_id, :presence => true 

见:http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html 3.9节的例子。

+0

实际上它是accepts_nested_attributes:HAS_ONE:化身:为=>:可成像,:依赖=>:破坏 的has_many:附件,:为=>:可附接,:依赖=>:破坏 accepts_nested_attributes_for:化身 –

+0

我做:reject_if =>:all_blank,它不允许我走得更远,但不显示错误消息。 –

+0

是否显示其他字段错误?也许你的代码显示错误是问题? –