views:

30

answers:

1

Hi, I have a complex form in Ruby on Rails 2.3.5, here's the structure for it: Artist - Name - Albums -Songs - Photos

Each artist can albums and several photos. For each album, there are several songs. I want to create a 3 step process. - Create Artist - Create Album (will have option to create multiple songs) - Create Photos

I want to set it up in a wizard-like way. My question is actually pretty general - how would you go about (organizationally speaking) creating forms for the models and controllers for such a project?

Currently, I have a model called Artist, a model called Albums and a model called Photos. Artists has many albums and photos. Under which view would I place the form?

Right now, the way it is looking I go to: artists/new - create the artist, somehow pass artist id to album, move to albums as albums/new, keep passing that artist id to photos, photos/new to create photos and then finish -> back to artists/show.

Ideally, I'd like to have something like artists/new/1 to create the artists artists/new/2 to create the albums and artists/new/3 to create the photos.

How would I go about doing that? Other than routing the pages to where I want them, is that the correct way of organizing things?

Thank you!

+1  A: 

You probably need nested routes. It automatically should handle relations.

So you will have links like artists/1/albums/new, artists/1/albums/5/songs/new etc

So your scenario could sound like this:

  1. artsists/new
  2. Save the artist on post.
  3. Redirect (or render ajax form) to new article (you can use rails generated helper) redirect_to new_artist_article_url @artist_just_created_and_saved
  4. Save artist and to the same for songs etc
Dmytrii Nagirniak
this looks promising, yet I am unclear about how to work it out when I am first creating an artist - I won't have its id yet. What would I do?
yuval
thanks so much!
yuval
Updated answer a bit with the details.
Dmytrii Nagirniak
ust have a look at the link I provided. Read it through (especially nested *RESOURCES*) and you will be fine
Dmytrii Nagirniak