Saving an array of objects

How do I save an array of obects into the database?

For now I am doing

for a in array
a.save
end.

I am sure there must be an easy way to do this.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Using a block is much concise…

array.each { |a| a.save! }

On Jun 20, 2006, at 12:59 AM, thila thila wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFEl4FYqvuZB2zXNU0RAud8AJ4/CQFSgmQkWVyR2L1mkNu7P6qyzACfRzJs
4U1P1m41zhp+G4yoo5z6Xh4=
=yGEV
-----END PGP SIGNATURE-----

afaik, you have to loop, you can’t just save them all. The only
shorter way is to use the more concise

array.each {|a| a.save}

Or even better… array.each(&:save)

-Jonathan.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs