我无法弄清楚为什么我的“shared/error_messages”部分没有在应该呈现的时候呈现(即当通过此表单提交无效的“处理”时):
_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 %>
这个 _treating_form.html.erb 部分在 users/show.html.erb 视图中调用:
<% 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>
这是我的 error_messages 部分:
<% 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 %>
在提交到用户“编辑设置”页面时触发验证错误时,error_messages 部分正确呈现:
<% 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>
任何想法为什么在提交无效的“处理”时没有显示错误?谢谢!