jeudi 27 octobre 2016

Assigning nested attributes to build_object

Is their a way to create this hash not to loop?

 {"0"=>{":comment_id"=>"52"}, "1"=>{":comment_id"=>"53"}, "2"=>{":comment_id"=>"15"}}

Output:

[{":comment_id"=>"52"}, {":comment_id"=>"53"}, {":comment_id"=>"15"}]

So it can perform:

@article = Article.new(article_params)
@article.build_comments([{":comment_id"=>"52"}, {":comment_id"=>"53"}, {":comment_id"=>"15"}])

@article.save

Aucun commentaire:

Enregistrer un commentaire