Rails inserting multiple records for single model

前端 未结 2 395
半阙折子戏
半阙折子戏 2021-01-23 06:03

How shall I set the form fields to be able to insert multiple rows in the database for a single model.

I am updating a div with another link and cannot use the form hel

相关标签:
2条回答
  • 2021-01-23 06:38
    posts = Array.new
    posts << {:title => "title 1"}
    posts << {:title => "title 2"}
    Post.create(posts)
    
    0 讨论(0)
  • 2021-01-23 06:57

    is this what you're trying to do?

    posts = []
    posts << Post.new(:title => "title 1")
    posts << Post.new(:title => "title 2")
    
    posts.each do |post|
      post.save
    end
    
    0 讨论(0)
提交回复
热议问题