rails3 I18n: can't override “1 error prohibited this packet from being saved:”

萝らか妹 提交于 2019-12-05 02:59:52

Doh! Found it! Stupid me!

In forgot that in rails 3 you no longer use error_messages_for, so instead in my scaffolded view code there was the following code:

 = form_for @packet do |f|
   -if @packet.errors.any?
     #errorExplanation
       %h2= "#{pluralize(@packet.errors.count, "error")} prohibited this packet from being saved:"

So, no wonder i could not translate that. Aaaaarrrgghh!!

The solution is either to use the dynamic-form plugin (which gives you the same functionality as in rails 2.3), or adapt the view accordingly, as i did:

  -if @packet.errors.any?
    #errorExplanation
      %h2
        - if @packet.errors.count == 1
          = t 'activerecord.errors.template.header.one', :model => @packet.class.human_name
        - else
          = t 'activerecord.errors.template.header.other', :model => @packet.class.human_name, :count => @packet.errors.count
      %b= t 'activerecord.errors.template.body'
      %ul
        - @packet.errors.full_messages.each do |msg|
          %li= msg

But, as we need to do this for each view possibly having errors, this should go into a partial, or use the plugin mentioned above :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!