0
我做了Rails中的表:通過值從查看到控制器動作
<table class="table_box">
<%= table_head([
{text: "wanted", width: "30%"},
{text: "Skill", width: "30%"},
{text: "Duration (In months)", width: "30%"},
{text: "Proficiency", width: "10%"}])%>
<tbody id="skill">
<% skills.each do |skill| %>
<tr class="<%= cycle("tr_box","tr_box odd",:name=>"details")%>">
<% contains_skill = user_skills.include? skill
indeex = user_skills.index(skill) if contains_skill
has_experience = (indeex ? user_experience[indeex] : '')
has_proficiency = (indeex ? user_proficiency[indeex] : '')
%>
<%= table_row([
{:text=>check_box_tag("checkbox[]",value = "1",checked = contains_skill)},
{:text=>skill},
{:text=> (number_field_tag 'quantity', has_experience, in: 1...5)},
{:text=> (select_tag "credit_card", options_for_select([ '','Expert', 'Average','Beginner' ], has_proficiency))},
])%>
</tr>
<% end %>
<div class="clear"></div>
</tbody>
</table>
現在我希望所有的參數(表值)進入我的控制器,所以我可以處理它們。我試着製作一個按鈕:
<%= button_to "New", action: "update" %>
但這沒有奏效。 我怎樣才能從表中的值到控制器?
使用表格:http://guides.rubyonrails.org/form_helpers.html –
嘗試過這種形式,但是我的實現不起作用 –
您需要將輸入字段包裝在表單標記中,該標記的行爲指向映射到您的路線控制器行動。另外,使用'submit_tag'而不是'button_to'。 http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-submit_tag –