开发者

Customizing header of error_messages_for

开发者 https://www.devze.com 2023-02-22 02:13 出处:网络
I\'m trying to get a custom error message using error_messages_for. I\'m using rails 3 and have downloaded and installed the plugin.

I'm trying to get a custom error message using error_messages_for. I'm using rails 3 and have downloaded and installed the plugin. In my view I have:

error_messages_for :model

Which works and gives me error messages. However I'm wanting to change the default

1 error prohibited this model from being saved

etc.

I've managed to change the attribute names using the local file:

en:
  activemodel:    
    attributes:
      model:
        dateOfBirth: 'Date of birth'
        etc

However when I try adding in:

activemodel:
    errors:
      template:
        header:
          one:    "{{model}} is not valid"
          other:  "There are {{count}} errors prohibiting this {{model}} from being saved"
        # The variable :count is also available
        body: "The following fields have problems:"

As suggested in rails guide it doesn't change the header and I don'开发者_开发知识库t get the new error messages.

I've tried both activemodel and activerecord.

Any help greatly appreciated


I think the issue is to do with the plugin that I'm using. Dynamic Form is not exactly the same as how rails 2.3.x handles errors. In that errors is not scoped under Active Record. Looking at the locale file that ships with this plugin:

en:
  errors:
    template:
      header:
        one:    "1 error prohibited this %{model} from being saved"
        other:  "%{count} errors prohibited this %{model} from being saved"
      body: "There were problems with the following fields:"

If I edit this file, then it works. Shortly be looking at whether this can be integrated into the plugin so it works same as 2.3.x

0

精彩评论

暂无评论...
验证码 换一张
取 消