Assuming Rails 1.2.x
Your routes will be something like:
Code:
map.resources :galleries do |gallery|
gallery.resources :photos
end
Now you will have URLs / Path's like ... galleries_path, photos_path(gallery), photo_path(glallery, photo)
in you controllers....
Code:
class GalleriesController < ApplicationController
# Show all galleies: /galleries (galleries_path)
def index
end
end
class PhotosController < ApplicationController
before_filter :find_gallery
attr_reader :gallery
helper_method :gallery
# Show photos for a given gallery
def index
# All your photos are in gallery.photos
end
# Show a photo: /galleries/:gallery_id/photos/:id (photos_path(gallery, photo))
def show
@photo = gallery.photos.find params[:id]
# Other stuff here
end
private
def find_gallery
@gallery = Gallery.find params[:gallery_id]
end
end
You won't need a show method in the galleries controller, as the photos controller index will be pretty much the same thing.
Bookmarks