答案 0 :(得分:0)
根据你的代码,我可以拿出来:
<%= form_tag "/book/view", method: :get do %>
<%= select_tag "id", options_for_select(books.collect{|book| ["#{book.name} #{book.id}", book.id] }) %>
<%= submit_tag "View Book Details" %>
<% end %>
<%= form_tag "/book/delete", method: :delete do %>
<%= select_tag "id", options_for_select(books.collect{|book| ["#{book.name} #{book.id}", book.id] }) %>
<%= submit_tag "Delete Book" %>
<% end %>
答案 1 :(得分:0)
您可以使用单选和单隐藏字段来完成此工作。
//form 1 for view
<%= form_tag "/book/view", method: :get do %>
<%= select_tag "id", options_for_select(books.collect{|book| ["#{book.name} #{book.id}", book.id] }),
:onChange => "$('#book_select').val($(this).val())" %>
<%= submit_tag "View Book Details" %>
<% end %>
//form 2 for delete
<%= form_tag "/book/delete", method: :delete do %>
<%= hidden_field_tag "book_select", :name => "id" %>
<%= submit_tag "Delete Book" %>
<% end %>