【发布时间】:2017-01-09 21:03:48
【问题描述】:
我正在从教程中学习 Rails 5.0,在该教程中它使用了我不熟悉的 f.object。 f.object 被传递到 ERb 中,传递到处理错误处理的方法中。
我知道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, 1..@subject_count) %></td>
</tr>
</table>
<% end %>
没有称为object 的HTML 表单元素,而这通常是在f. 之后出现的,所以真的很讨厌它可能是什么。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5