f.error_messages in Rails 3.0

前端 未结 6 1014
难免孤独
难免孤独 2020-11-29 00:04

Rails 3.0 deprecated f.error_messages and now requires a plugin to work correctly - I however want to learn how to display error messages the (new) native way.

6条回答
  •  [愿得一人]
    2020-11-29 00:18

    This functionality exists as a standalone gem dynamic_form.

    Add the the following to your Gemfile

    gem 'dynamic_form'
    

    From the github page:

    DynamicForm holds a few helpers method to help you deal with your Rails3 models, they are:

    • input(record, method, options = {})
    • form(record, options = {})
    • error_message_on(object, method, options={})
    • error_messages_for(record, options={})

    It also adds f.error_messages and f.error_message_on to your form builders.

提交回复
热议问题