# Help with passing data between scaffolds

**URL:** <https://www.ruby-forum.com/t/help-with-passing-data-between-scaffolds/159783>\
**Category:** Rails\
**Created:** [February 8, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/help-with-passing-data-between-scaffolds/159783 "2009-02-08T19:11:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thegoatboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc348/32.png) [@thegoatboy](https://www.ruby-forum.com/u/thegoatboy)\
**Post date:** [February 8, 2009, 7:11pm UTC](https://www.ruby-forum.com/t/help-with-passing-data-between-scaffolds/159783/1 "2009-02-08T19:11:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thegoatboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc348/32.png) [@thegoatboy](https://www.ruby-forum.com/u/thegoatboy)\
**Post date:** [February 9, 2009, 9:20am UTC](https://www.ruby-forum.com/t/help-with-passing-data-between-scaffolds/159783/2 "2009-02-09T09:20:34Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
