views:

18

answers:

1

Hello,

I've created:

PhotoAlbum (id, name)
  has_many: photos
Photo (id, name, photo_album_id)
  belongs_to: photo_album

I want to allow a user to upload 1 or more photos. Per Upload whether it be 1 or more photos, they should automatically be added to a new album.

So the way i have it is, a user clicks upload photos: They get the photo view where they get the form. They can then upload 1 photo (in the future I want to support more than 1, but baby steps!

so now in my Photos Controller, I have DEF CREATE

Q: How in the DEF CREATE, do I auto create an album and then create the photos? Something like?

@photo_album = PhotoAlbum.create
@photo = @photo_album.create(params[:photo]) 

? Is this the right Rails way to do this?

Thanks

A: 
@photo_album = PhotoAlbum.create({:name => "My Photo Album"})
@photo = @photo_album.photos.build({:name => params[:photo]})

I'm assuming your params[:photo] is the name, but you get the idea.

porkeypop