2017-02-27 12 views
0

私はドロップダウンの代わりに #<Sponsorship::ActiveRecord_Associations_CollectionProxy:0x007f99a874bcd0> のテキストボックスを持つコレクションを表示しているbillというモデルのフォームにコレクションを持っています。何か案は? Rails 4 CollectionProxyエラー

... 
.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' 
... 
_form.html.haml

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" 

真:あなたは複数受け入れる場合、これが起こるかもしれないsimple_formで

_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

。 そうでなければ、これは十分なはずです:

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

さらに、お使いのコントローラの方法で利用可能に@congress_peopleニーズ。

+0

私はhamlを使用しています。開始タグと終了タグは使用しません。 – Taylor

+0

私は_sponsors_fields.html.hamlでその正確な入力を使用し、私はmultiple:trueを使用しません。それは連想エラーなので、私のモデルとは関係があると思っていますが、私はそれを理解することができませんでした。 – Taylor

+0

@congress_peopleを見つけて、正しい入力を得られるようにしてください –