2017-02-27 83 views
0

我在表單上顯示了一個名爲bill的模型集合,它使用文本框 #<Sponsorship::ActiveRecord_Associations_CollectionProxy:0x007f99a874bcd0> 而不是下拉菜單顯示集合。有任何想法嗎?Rails 4 CollectionProxy錯誤

bill.rb
class Bill < ActiveRecord::Base 
     belongs_to :congress_person 
     has_many :bps, :dependent => :destroy 
     has_many :committees, :dependent => :destroy 
     has_many :sponsorships, -> { where(kind: :primary) }, class_name: "Sponsorship" 
     has_many :cosponsorships, -> { where(kind: :secondary) }, class_name: "Sponsorship" 

     has_many :sponsors, class_name: 'CongressPerson', through: :sponsorships 
     has_many :cosponsors, class_name: 'CongressPerson', through: :cosponsorships 

congress_people.rb
has_many :sponsorships, -> { where(kind: :primary) }, class_name: "Sponsorship", foreign_key: :sponsor_id 
    has_many :cosponsorships, -> { where(kind: :secondary) }, class_name: "Sponsorship", foreign_key: :sponsor_id 

    has_many :sponsored_bills, through: :sponsorships, source: :bill 
    has_many :cosponsored_bills, through: :cosponsorships, source: :bill 

sponsorship.rb
belongs_to :bill 
belongs_to :sponsor, class_name: "CongressPerson" 
belongs_to :cosponsor, class_name: "CongressPerson" 

_form.html.haml
... 
.row-fluid 
       .col-md-12 
        %h3 Sponsor 
        #sponsors-form 
         = f.simple_fields_for :sponsors do |sponsor| 
          = render 'sponsor_fields', f: sponsor 
         .links 
         = link_to_add_association 'Add Sponsor', f, :sponsors, class: 'btn btn-secondary add-button' 
... 

_sponsors_fields.html.haml

.form-inline.clearfix 
    .row 
     .nested-fields 
      = f.input :sponsorships, :collection => @congress_people 

      = link_to_remove_association "Remove", f, class: "form-control btn btn-secondary", style: 'height:20%; display:inline; float:right;' 

回答

0

隨着simple_form如果你接受這個倍數可能發生:真。 否則,這已經足夠了:

= f.input :sponsorships, :collection => @congress_people 

此外,@congress_people需要提供您的控制器方法。

+0

我使用haml它不使用開始和結束標記。 – Taylor

+0

我在_sponsors_fields.html.haml中使用了確切的輸入,並且不使用multiple:true。由於這是一個關聯錯誤,我認爲它與我的模型有關,但我一直無法弄清楚。 – Taylor

+0

你應該嘗試找到@congress_people並確保它獲得正確的輸入 –