Rails inserting multiple records for single model

前端 未结 2 430
半阙折子戏
半阙折子戏 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: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
    

提交回复
热议问题