0
我與使用fields_for操作嵌套的子表單有一對多的關係。如何設置一個field_for子表單的字段的error_message_on
我想使用內置的rails錯誤處理在使用error_message_on方法的孩子上顯示錯誤消息。
例子:
<% form_for @business, :url => {:action => :page, :page => @page}, :html => {:method => :put } do |f| -%>
<h5><strong>More Details</strong></h5>
<div class="clear"></div>
<div class="col-1">
<label for="hours">Hours</label>
<table class="hours">
<tbody>
<% f.fields_for :hours do |hours_form| %>
<tr>
<td><%= hours_form.label :day, hours_form.object.day %>:<%= hours_form.hidden_field :day %></td>
<td><%= hours_form.text_field :open_time, :class => 'input' %></td>
<td>to</td>
<td><%= hours_form.text_field :close_time, :class => 'input' %></td>
<td><%= hours_form.check_box :closed %></td>
<td class="c6"><%= hours_form.label :closed, 'Closed this day' %>
<%= hours_form.error_message_on :open_time, :css_class => 'cant-be-blank' %>
<%= hours_form.error_message_on :close_time, :css_class => 'cant-be-blank' %></td>
</tr>
<% end -%>
</tbody>
</table>
...