Customize error message with simple_form

后端 未结 4 1882
一向
一向 2020-12-29 13:57

I\'m using the simple_form gem. I want to customize the error message displayed when a user fails validations. How can I accomplish this?

4条回答
  •  悲哀的现实
    2020-12-29 14:32

    You can easily change the default error message comes in the translation file, which is found in config/locales/simple_form.en.yml.

    In the specific initializer, config/initializers/simple_form.rb you can overrule the default options how the html is generated.

    Hope this helps.

    For completeness, I would like to add that formtastic is an easier choice to start with, because it has a default layout. I like simple_form a lot, but it does not offer any formatting out of the box, but that is their intention. With Formtastic it is very hard (impossible) to change the generated html, and with simple_form can you can completely mold the generated html to your liking. This is especially useful if you have a designer, and the forms you generate have to generate the same html. So if you are getting started, formtastic will give you nicer-looking results quicker. Also note that it is quite easy to switch, because the syntax is almost identical.

提交回复
热议问题