Reputation: 7210
I need to sort of add a secondary show action to my Photos controller. I have named it fullscreen.
My show action shows a photo in the center of the page and the fullscreen action will take over the page and show the photo as large as it can be.
How would I set this up in my router and what would the link be like on the image on the view that rendered for the Photo Show action?
Just wondering how all this fits together?
Here is my Photo Controller:
class Gallery::PhotosController < Gallery::GalleryController
def index
@photos = Photo.all
end
def show
@photo = Photo.find(params[:id])
@album = Album.where(id: @photo.album_id).first
@first_of_album = Photo.where(album_id: @album.id).first
@last_of_album = Photo.where(album_id: @album.id).last
respond_to do |format|
format.html
format.js
end
end
def fullscreen
@photo = Photo.find(params[:id])
@album = Album.where(id: @photo.album_id).first
@first_of_album = Photo.where(album_id: @album.id).first
@last_of_album = Photo.where(album_id: @album.id).last
end
end
and my router for this part:
namespace :gallery do
resources :collections, only: [:index, :show] do
resources :albums, only: [:index, :show] do
resources :photos, only: :show
end
end
end
I take it I can't use a link helper as Rails won;t have generated one without an applicable route but i'm not sure how to erm 'plumb' this in at the router side?
Any thoughts?
Upvotes: 0
Views: 77
Reputation: 115541
Do this:
resources :photos, only: :show do
member do
get :fullscreen
end
end
Upvotes: 1