FormHelper::ErrorMessages
Extend ActionView::Helepr::FormHelper for rendering error message on any position.
Installation
Add this line to your application's Gemfile:
gem 'form_helper-error_messages'
And then execute:
$ bundle
Or install it yourself as:
$ gem install form_helper-error_messages
Usage
# You can put error message any position.
<%= from_for(@user) do |f| %>
<%= f.text_field :name %>
<%= f.error_messages :name %>
<% end %>
# <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div>
# <div class="invalid">Name can't be blank</div>
# </form>
You can choose any tags or any class name like this.
<%= from_for(@user) do |f| %>
<%= f.text_field :name %>
<%= f.error_messages :name, tag: 'span', class: 'error' %>
<% end %>
# <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
# <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /></div><span class="error">Name can't be blank</span></form>
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request