Why doesn't Rails' “errors.full_messages” replace attribute and message variables?

后端 未结 8 1677
小鲜肉
小鲜肉 2020-12-09 16:22

Having a strange problem with a rails model I just created.

Here are my validations:

validates_presence_of :from_name, :message => \'Please provid         


        
8条回答
  •  感情败类
    2020-12-09 16:58

    I'm working on a Rails 2.3.5 server at work that doesn't have i18n gem. The odd thing is that while my code works locally, I have this problem on the work server. And, another application I have with the same exact frozen gems does not display this problem on the work server.

    I changed the activerecord en.yml file like above but also changed the actionpack en.yml file to get the error message title/header right:

       \vendor\rails\activerecord\lib\active_record\locale\en.yml
    
        #format: "{{attribute}} {{message}}"
         format: "%{attribute} %{message}"
    
        \vendor\rails\actionpack\lib\action_view\local\en.yml
    
          activerecord:
            errors:
              template:
                header:
                  one:    "1 error prohibited this %{model} from being saved"
                  other:  "%{count} errors prohibited this %{model} from being saved"     
    

    Also, I didn't bother with it but if you have error messages that contain counts, it looks like in the activerecord en.yml file you'd need to change the syntax of some of the messages too (like):

    #too_long: "is too long (maximum is {{count}} characters)"
    too_long: "is too long (maximum is #{count} characters)"
    

提交回复
热议问题