2017-10-26 4 views
0

と、ArgumentErrorが動作していないbelongs_toの関連は名前 `顧客件見つかりました。それはまだ定義されていますか?Railsの関連付けにhas_manyとProposalsControllerの#インデックス</p> <p>に

このエラーは私のアプリにはあります。解決策を見つけることができません。何か案は?ここで

はモーダルです:ここでは

class Client < ActiveRecord::Base 
    has_paper_trail 

    has_many :documents 

    accepts_nested_attributes_for :documents, allow_destroy: true, reject_if: :all_blank 

end 

class Document < ActiveRecord::Base 
    has_paper_trail 

    belongs_to :client 

    accepts_nested_attributes_for :clients, allow_destroy: true, reject_if: :all_blank 

    validates :name, presence: true 
end 

ドキュメント用のコントローラです:

def index 
    if current_user.admin? 
     @documents = Document.paginate(page: params[:page], :per_page => 20) 
    else 
     @documents = Document.where("user_id = ?", current_user).paginate(page: params[:page], :per_page => 20) 
    end 
    end 
  1. 私はドキュメントのためのDBに "CLIENT_ID" を入れています。
  2. 安全なパラメータを両方のコントローラに入れました。
+1

あるので、:clientsaccepts_nested_attributes_forに単数形でなければなりませんが、あなたは 'ProposalsController#1 index'からあなたのコードが含まれてもらえますか?ここの定義から 'document.client'を呼び出すことはできますが、' document.clients'は呼び出さないことに注意してください。 – Julie

+0

@Julieが追加されました。しかし、try/documents/new errorがProposalsController#newでない場合。コントローラ内のすべてのメソッドで発生します。 – DanielsV

答えて

1

あなたはほとんど存在していますが、ちょっとした細部を見逃しました。常にインタプリタ/コンパイラの言うことに従ってください。何が間違っているのかを知ることができます。あなたのケースでは

それはbelongs_toの

class Document < ActiveRecord::Base 
    has_paper_trail 

    belongs_to :client 

    accepts_nested_attributes_for :client, allow_destroy: true, reject_if: :all_blank 

    validates :name, presence: true 
end 
関連する問題