2017-01-31 3 views
0

私はモデルActesとモデルを持っています。お互いの関係でhabtmです。強力なパラメータを使ってネストされた属性を取得する

新しいアクテフォームをサーバーに送信すると、強力なパラメータを取得できません。

これはparams[:acte]である:

"acte"=>{ 
     "biblio_id"=>"1", 
     "acte_numero"=>"12", 
     "keywords_attributes"=>{"0"=>{"keyword"=>"attestation, "}}, 
     "texte"=>"<p>test</p>", 
     "complement"=>"" 
     } 

モデルacte.rbは含まれています

has_and_belongs_to_many :keywords 
belongs_to :user, optional: true 
belongs_to :biblio, optional: true 
belongs_to :archive, optional: true 
has_many :comments 

accepts_nested_attributes_for :keywords, allow_destroy: true, 

注:私はaccepts_nested_attributes_forreject_if: :all_blankを追加した場合、フォームはまったく送信されません。

これはacte_controllerである:

def params_acte 
    params.require(:acte).permit(:biblio_id, 
           :acte_numero, 
           :keywords_attributes =>[:keyword], 
           : resume, 
           # cut for brievity 

これは、あなたが最後にkeywords_attributesを追加する必要がありますsyntax error, unexpected ',', expecting => :resume, ^

答えて

2

を誘発します。

def params_acte 
    params.require(:acte).permit(:biblio_id, 
           :acte_numero, 
           :resume, 
           # All other model attributes 
           :keywords_attributes =>[:keyword], 

これは動作します。

注:必ず終わる

でネストされた属性を追加
関連する問題