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.
Installation¶ ↑
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:
-
_error_messages.html.*
-
template for error_messages_for
-
_error_message.html.*
-
template for error_message_on
You can freely modify views listed above.
Overriding templates¶ ↑
In _error_messages
you can use following local variables:
-
object
-
main object passed in arguments (or associated with form)
-
objects
-
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 %ul - objects.each do |o| - o.errors.full_messages.each do |msg| %li= msg
In _error_message
there are following local variables:
-
object
-
object passed in arguments (or associated with form)
-
field
-
field name passed in arguments
-
error
-
error message
Usage¶ ↑
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¶ ↑
Copyright © 2010 Kriss ‘nu7hatch’ Kowalik. See LICENSE for details.