PrivateUser
PrivateUser

Reputation: 4534

How to batch-create posts?

I have a bookmark controller which has the seven default RESTful actions.

I would like to have a form for batch bookmark creation.

It's going to have a textarea field where the user can enter URLs, one URL per line.

Upon submission, I would like to bulk-insert those URLs into the database.

Can someone help me to achieve this?

Upvotes: 2

Views: 563

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

Hard to know without seeing your form, the field and the controller, but here we go.

 params[:urls].split("\n").each do |url|
   PostUrl.create(url: url)
 end

Upvotes: 4

Related Questions