将值从视图传递到控制器操作

时间:2016-12-22 14:28:29

标签: html ruby-on-rails ruby

我在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" %>

但这不起作用。 如何将表中的值导入控制器?

1 个答案:

答案 0 :(得分:0)

如果表单的复杂程度超过最简单的表单那么简单形式的gem可能是一个很大的帮助。

请在此处查看:https://github.com/plataformatec/simple_form

它允许您基于模型或视图模型创建表单。除此之外,它还有很好的记录。