我是HTML和RoR的新手。我尝试在表旁边提供一个提交隐藏表单的按钮。但是由于某种原因,该按钮未显示在生成的HTML中。
<table class="centerBox">
<h3>Search Results:</h3>
<thead>
<tr>
<th>Name</th>
<th>Code</th>
<th>Subject_id</th>
</tr>
</thead>
<tbody>
<% @searchResults.each do |searchResult| %>
<tr>
<td><%= searchResult.name %></td>
<td><%= searchResult.code %></td>
<td><%= searchResult.subject_id %></td>
<td>
<% form_for(:enrollment, url: enroll_path) do |f| %>
<div class="actions">
<%= f.hidden_field(:enrollment, :course_name => searchResult.name)%>
<%= f.hidden_field(:enrollment, :user_id => current_user) %>
<%= f.submit "Enroll"%>
</div>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
生成的HTML:
<tr>
<td>Independent Study</td>
<td>AAAS 98B</td>
<td>1161-100</td>
<td>
</td>
</tr>
答案 0 :(得分:3)
要使erb代码打印您调用的方法的输出,您需要对= <%=%>标签使用=,就像对字段和提交按钮所做的一样。
<%= form_for(:enrollment, url: enroll_path) do |f| %>
<div class="actions">
<%= f.hidden_field(:enrollment, :course_name => searchResult.name) %>
<%= f.hidden_field(:enrollment, :user_id => current_user) %>
<%= f.submit "Enroll"%>
</div>
<% end %>