2016-08-11 108 views
0

我有一个代码,循环通过每个投标人,并尝试创建一个输入框,以指派所有者更新每个特定出价人的特定出价的状态。Ruby on Rails单表格使用循环更新多个记录

<div id="titlebar" class="single submit-page"> 
 
    <div class="container"> 
 

 
    <div class="col-lg-10"> 
 
     <h2><i class="fa fa-bell"></i> Bidders</h2> 
 
    </div> 
 

 
    <!-- <div class="col-lg-2"> 
 
     <br> 
 
     <button type="button" class="btn btn-primary btn-lg"> 
 
      <i class="fa fa-list-alt"></i> Find Assignments 
 
     </button> 
 
    </div> 
 
    --> 
 
    </div> 
 
</div> 
 

 
<div class="container"> 
 
    
 
    <!-- Table --> 
 
    <div class="col-lg-12"> 
 

 
    <p class="margin-bottom-25"> Bids can be viewed or removed below.</p> 
 

 
    <table class="manage-table resumes responsive-table"> 
 

 
     <tr> 
 

 
     <th><i class="fa fa-genderless"></i> Gender</th> 
 
     <th><i class="fa fa-clock-o"></i> Experience</th> 
 
     <th><i class="fa fa-graduation-cap"></i> Education Level</th> 
 
     <th><i class="fa fa-money"></i> Expected Salary</th> 
 
     <th><i class="fa fa-file-text"></i> Status</th> 
 
     <th></th> 
 
     </tr> 
 

 
     <!-- Item #1 --> 
 
     
 
     <tbody> 
 
     <% @bidders.each_with_index do |bidder, i| %> 
 
      <tr> 
 
      <% if bidder.gender == 1 %> 
 
      <td>Male</td> 
 
      <% else %> 
 
      <td>Female</td> 
 
      <% end %> 
 

 
      <td><%= bidder.experience %></td> 
 
      <td><%= bidder.education.education %></td> 
 
      <td><%= bidder.expected_salary %></td> 
 
      <td><%= bidder.bid.status %></td> 
 
      <%= form_for(@bids[i]) do |f| %> 
 
      <td><%= f.label :status %> and <%= f.text_field :status %></td> 
 
      <% end %> 
 
      <td class="action"> 
 
      <a href="#"><i class="fa fa-eye-slash"></i> Hide</a> 
 
      <a href="#" class="delete"><i class="fa fa-remove"></i> Delete</a> 
 
      </td> 
 
     </tr> 
 

 
     <!-- Item #1 --> 
 
     <% end %> 
 
     </tbody> 
 
     
 
    </table> 
 

 
    </div> 
 

 
</div>

application_controller.rb:

def bidders 
    bidders_ids = Bid.where(bidders_params).pluck(:user_id) 
    @bidders = User.where(id: bidders_ids) 
    @bids = Bid.where(bidders_params) 
end 

bids_controller.rb:

def bid_params 
    params.require(:bid).permit(:status, :assignment_id, :user_id) 
    #params.permit(:status, :assignment_id, :user_id) 
    end 

的问题是环路创建多个形式。

  1. 我想只有一种形式,但多选择下拉菜单中的选项1..X根据投标人的总数上出于排名目的,这个特殊的任务。

  2. 我想确保一旦点击提交按钮(我没有包括),所有多个:状态字段将在数据库中更新到它们各自的记录中。

+0

你需要的东西,比如x编辑[演示链接(https://开头vitalets。 github.io/x-editable/demo-bs3.html) –

+0

https://github.com/werein/x-editable-rails –

回答

0

是这样的吗?

X编辑将创建远程true的形式为每个属性,你想改变

enter image description here

+0

就是这样的。但我需要将它链接到数据库。换句话说,这个表格必须提交并更新到表格中。我怎样才能做到这一点? – Benjamin

+0

请查阅更多信息http://railscasts.com/episodes/302-in-place-editing –

+0

谢谢!看起来像我正在寻找的东西。我会试试看! – Benjamin