I can’t figure out why my ‘shared/error_messages’ partial isn’t being rendered when it should be (i.e. when an invalid ‘treating’ is submitted through this form):
_treating_form.html.erb:
<%= form_for(@treating) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div><%= f.hidden_field :requestee_id %></div>
<div>
<%= f.text_field :proposed_location, placeholder: "Propose a location here..." %>
</div>
<div>
<%= f.text_field :proposed_date, placeholder: "Propose a date here..." %>
</div>
<div class="field">
<%= f.text_area :intro, placeholder: "Write your introduction here..." %>
</div>
<%= f.submit "Send", class: "btn btn-large btn-primary" %>
<% end %>
This _treating_form.html.erb partial is called in a users/show.html.erb view:
<% provide(:title, @user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= @user.name %>
</h1>
</section>
<% if signed_in? %>
<section>
<%= render 'shared/treating_form' unless current_user?(@user) %>
</section>
<% end %>
</aside>
</div>
Here is my error_messages partial:
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
The error_messages partial is correctly being rendered upon validation errors triggered in submitting to user ‘edit settings’ page:
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
Any ideas why the errors aren’t being shown when an invalid ‘treating’ is being submitted? Thanks!
Whenever you add ANY options to a partial you need to explicitly specify :partial =>