Forum: Ruby on Rails Help with passing data between scaffolds

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E41db95ac505d785fddc8f2a62e05c0a?d=identicon&s=25 Steven Price (thegoatboy)
on 2009-02-08 19:11
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
8da92d4ed91aa12535f6d870fa76b25e?d=identicon&s=25 Aaron Baldwin (Guest)
on 2009-02-09 09:20
(Received via mailing list)
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 Price <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.