Rails 3.0中的自定义验证消息

时间:2011-09-07 22:23:18

标签: ruby-on-rails ruby validation

当我使用以下验证时:

 validates_length_of :lgtitle, :maximum=>45, :message=>"Please reduce the number of characters used in the Before Like Title. The maximum is 45 characters."

Rails在我的视图中返回消息和表格行:

Lgtitle Please reduce the number of characters used in the Before Like Title. The maximum is 45 characters.

消除添加到验证消息的表格表格字符串的最佳做法是什么?

谢谢。

1 个答案:

答案 0 :(得分:1)

model.errors中添加的错误消息为Hash

  • 键是列名

  • 值,消息本身

我打赌你会显示关键和值。