【发布时间】:2019-02-09 16:16:51
【问题描述】:
我正在为 Ruby on Rails 中的演示文稿开发一个注册应用程序。因此,我正在显示一个可用演示文稿的列表,最后一列显示一个用于注册该特定演示文稿的按钮。
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">Name</th>
# ...
</tr>
</thead>
<tbody>
<tr>
<% @presentations.each do |pres| %>
<td scope="row"><%= pres.Name %></td>
# ...
<td scope="row">
<% unless @current_student.Selected == pres.Titel %>
<%= form_tag students_select_path do %>
<%= submit_tag "Choose", class: "btn", value: pres.Title %>
<% end %>
</td>
</tr>
</tbody>
</table>
我希望按钮说出"Choose",然后将参数pres.Title 发送给我定义的函数。出于某种原因,表中的按钮显示了pres.Title 的值,而不是"Choose" 的值。如何解决这个问题?
当前的工作实现:
def addtodb
@student = Student.find_by(id: session[:student_id])
if @student.Selected == nil
prestitle = params[:commit]
@schueler.update_attribute(:Selected, prestitle)
redirect_to students_select_path
end
end
【问题讨论】:
-
我会改用 JavaScript 解决方案。表格不应该放在表格行内。你可以在这里阅读更多信息:stackoverflow.com/questions/5967564/form-inside-a-table/5967613
标签: html ruby-on-rails ruby forms erb