Form validation errors helper for Padrino
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Padrino form errors helper

This plugin is overriding standard error_messages_for and error_message_on. Now you can decide in which template will be displayed your validation messages.


Install plugin via rubygems:

gem install padrino-form-errors

And register plugin in your app.rb file:

class MyApp < Padrino::Application
  register Padrino::Helpers
  register Padrino::Mailer
  register Padrino::FormErrors
  # ...

Now you can run generator:

padrino-gen form_errors

Now in app/views/shared you'll two new partials should be present:


template for error_messages_for


template for error_message_on

You can freely modify views listed above.

Overriding templates

In _error_messages you can use following local variables:


main object passed in arguments (or associated with form)


list of all objects passed in arguments

You can display all errors using #errors method from specified object, eg:

%h3= #{object.class.human_name} couldn't be saved
  - objects.each do |o|
    - o.errors.full_messages.each do |msg|
      %li= msg

In _error_message there are following local variables:


object passed in arguments (or associated with form)


field name passed in arguments


error message


You don't have to learn nothing new about how to use functionalities provided by this plugin. Like I said it overrides standard helpers, so when you will write…

- form_for @user, url(:users_create) do |f|
  = f.error_messages
  -# ...

…then error messages for this form will be displayed using from your shared templates. The same is with error_messages_for and error_message_on.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don't break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.


Copyright © 2010 Kriss 'nu7hatch' Kowalik. See LICENSE for details.