2016-08-11 10 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が必要です変更したいため。 github.io/x-editable/demo-bs3.html) –

+0

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

答えて

0

このようなものは何ですか? // vitalets:

X-編集可能なリモート真でフォームを作成するには、各属性が、あなたは

enter image description here

+0

そうですね。しかし、私はそれをデータベースにリンクする必要があります。つまり、このフォームを送信してテーブルに更新する必要があります。どうやってやるの? – Benjamin

+0

詳細をご覧くださいhttp://railscasts.com/episodes/302-in-place-editing –

+0

ありがとう!私が探しているもののように見えます。私はそれを試してみます! – Benjamin

関連する問題