2016-08-11 66 views
0

注意:請參閱此鏈接獲取更新的問題。我已經改寫我的問題是試圖一段時間後,其他更簡潔:Ruby on Rails single form to update multiple records using loopRuby on Rails通過表格進行多表查詢

我有一個頁面來顯示特定項目的所有投標人與bidders.html.erb如下:

<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 do |bidder| %> 
 
     <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> 
 
     <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是:

class ApplicationController < ActionController::Base 
 
    # Prevent CSRF attacks by raising an exception. 
 
    # For APIs, you may want to use :null_session instead. 
 
    protect_from_forgery with: :exception 
 
    
 
    def bidders 
 
    bidders_ids = Bid.where(bidders_params).pluck(:user_id) 
 
    @bidders = User.where(id: bidders_ids) 
 
    end 
 
    
 
    def after_sign_in_path_for(resource) 
 
    assignments_path #your path 
 
    end 
 

 
end

的數據庫設計或多或少被描述如下:

enter image description here

的問題是,我需要與bidders.html.erb腳本轉換爲一個表單,允許幫助該特定項目的所有者通過將bidder.bid.status編輯爲排名數字來接受並排名多個投標人。

請注意,用戶可以是投標人,也可以創建項目供他人投標。

回答

0

它看起來像有造型的問題,在您的應用程序

也許這種方式應該會更好。

user.rb

def class User < ActiveRecord::Base 
    has_many :bids, class_name: 'Bid', :foreign_key => "user_iduser" 
end 
#controller.rb
def bidders 
    @user = User.find(params[id) 
end 
#鑑於
<% @user.bids.each do |bidder| %> 
    <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> 
    <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 %> 

分析數據庫設計和在這裏看起來像你想有一個協會has_many :through,更多信息在guides rails

您需要查看有關n的更多信息相關捐資形成http://guides.rubyonrails.org/form_helpers.html#building-complex-forms

+0

我想這: http://stackoverflow.com/questions/38900349/ruby-on-rails-single-form-to-update-multiple-records-using-loop 更好地代表我的問題 – Benjamin