Help with passing data between scaffolds

Hello everyone.

Great forum you have here.

I am pretty new to rails, and I am struggling getting an application up
and running.

My application is to have a photo gallery. I have two scaffolds, one for
albums, and one for the photos.

I have the albums section working smoothly, but I am having trouble
linking the both of them together.

I will try to explain my problem.

In the albums sections, I create and album. From the show.html you get
the option to view pictures.

<%= link_to (‘View Pictures’, :controller => ‘photos’, :action =>
‘list’, :album_id => @album.id) %>

from there, you are presented with a list of the photos contained in the
album.

Now, here is my problem.

To get the list of photos contained in an album, I am using the id of
the album to separate the photos.

so in my photos controller I have

@photos = Photo.paginate(:all,
:conditions => [‘album_id = ?’, @album.id],
:per_page => 9,
:page => params[:page])

which i can understand.

The big problem I have is storing the album ID to the new photo.

So from the ‘view pictures’ page, i have a link to 'add a photo, which
is my new.html.erb.

What I can’t do, is store a photo to the database / application, and
have the album_id stored to the photo also.

Every time i add a photo, the album id is not stored.

I have tried to add a hidden field, but whatever I do i cannot pass the
album id over to the new photo.

does anyone have any pointers for me?

I can add any extra bits of code as needed.

thegoatboy

A hidden field on the new form with the album_id should work. Start
by viewing the source of the form. Is the hidden field present and
does it have the correct value? If that looks ok, then review your
controller create action and finally your model to determine a what
point the album_id is being removed.

On a side note unrelated to your problem your photo controller index
action could be changed to this:

@photos = @album.photos.paginate(:all,
:per_page => 9,
:page => params[:page])

(Assuming album has_many photos in your model)

Aaron

On Feb 8, 11:11 am, Steven P. [email protected]