Reputation: 6756
I try to use simple_form for make my form view more readible
It looks now like this:
<%= simple_form_for @some_object, url: some_url, :html => {:class => 'form-horizontal' } do |f| %>
<%= f.error_messages %>
<%= f.input :phone %>
<div class="form-row">
<%= f.submit "Submit", :class => 'btn btn-primary' %>
<a class="btn btn-link" href="<%= object.to_url %>" title="Cancel" data-event="post_cancel_click"><span>Cancel</span></a>
</div>
<% end %>
Unfortunately I receive undefined method
error_messages' for SimpleForm::FormBuilder:0xb385c948`
When I don't use error_messages then form is rendered, but when error occurs it is not showed.
Upvotes: 1
Views: 1873
Reputation: 5095
That's as far as I know correct. Simple form doesn't know what 'error_messages
' is. When you check the documentation, it states:
<%= simple_form_for @user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
This will generate an entire form with labels for user name and password as well, and render errors by default when you render the form with invalid data (after submitting for example).
I believe there might be at least two solutions for your problem:
1) You can specify in your simple_form.rb initializer file with which tag your error message will be wrapped, like this:
b.use :error, :wrap_with => { :tag => :span, :class => :error }
Check here for more or in docs
2) Use f.error
helper, like it is described in docs
Upvotes: 1