我正在學習一個教程的Rails 5.0,在那個教程中它使用了我不熟悉的f.object
。將f.object
傳遞給ERb,轉換爲處理錯誤處理的方法。f.object在Rails表單生成器中做了什麼?
我知道f
是傳入表單的記錄的對象/實例。但我不明白的是f.object
。
edit.html.erb(與窗體文件):
<%= form_for(@section) do |f| %>
<%= error_messages_for(f.object) %>
<table summary="Subject form fields">
<tr>
<th>Name</th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th>Position</th>
<td><%= f.select(:position, [email protected]_count) %></td>
</tr>
</table>
<% end %>
沒有被稱爲object
HTML表單元素,而這就是f.
以後有什麼一般無二,於是真的就可能是什麼惱火。