Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johno/form_errors
Clean up form error reporting in Rails with a nice little view helper.
https://github.com/johno/form_errors
Last synced: 9 days ago
JSON representation
Clean up form error reporting in Rails with a nice little view helper.
- Host: GitHub
- URL: https://github.com/johno/form_errors
- Owner: johno
- License: mit
- Created: 2014-04-10T15:32:31.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-17T03:20:00.000Z (about 9 years ago)
- Last Synced: 2024-10-19T17:29:55.183Z (4 months ago)
- Language: Ruby
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Form Errors
Clean up form error reporting in Rails with a nice little view helper.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'form_errors'
```And then execute:
```
$ bundle
```Or install it yourself as:
```
$ gem install form_errors
```## Usage
To display errors in your Rails form, you can call the `display_errors` view helper and pass along the object.
```html+erb
<%= simple_form_for(@product, html: { class: "form-horizontal" }) do |f| %>
<%= display_errors(@product) %>
<% end %>
```If you'd like to customize the error string within the `h2` tag, you can add a second parameter.
```html+erb
<%= simple_form_for(@product, html: { class: "form-horizontal" }) do |f| %>
<%= display_errors(@product, "We were unable to save that product.") %>
<% end %>
```The helper applies the `alert`, `alert-danger`, and `alert-dismissable` classes to the wrapper element. It also includes a `data-dismiss`. If you're using bootstrap, it ties in perfectly.
```html
×
We were unable to save that product.
- Name can't be blank
- Product definition can't be blank
```The `h2` message defaults to:
```ruby
"#{ pluralize(object.errors.count, "error") } "\
"prohibited this #{ object.class.name.underscore.humanize.downcase } "\
"from being saved"
```You can also pass html classes to the different DOM elements with:
```ruby
display_errors(@object, 'Whoopsie', error_string_class: 'h4')
```## Contributing
1. Fork it ( http://github.com/johnotander/form_errors/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request