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. -- Posted via http://www.ruby-forum.com/.
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}
On 6/19/06, thila thila <isputnik_98@yahoo.com>
wrote:> 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.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-----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:
> 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.
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFEl4FYqvuZB2zXNU0RAud8AJ4/CQFSgmQkWVyR2L1mkNu7P6qyzACfRzJs
4U1P1m41zhp+G4yoo5z6Xh4=yGEV
-----END PGP SIGNATURE-----
Or even better... array.each(&:save) -Jonathan. On 6/20/06, Pat Maddox <pergesu@gmail.com> wrote:> 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} > > On 6/19/06, thila thila <isputnik_98@yahoo.com> wrote: > > 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. > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >