【发布时间】:2014-02-18 23:09:35
【问题描述】:
我需要在我的照片控制器中添加一个辅助显示操作。我已将其命名为全屏。
我的显示动作在页面中心显示一张照片,全屏动作将占据页面并尽可能大地显示照片。
我将如何在我的路由器中进行设置,以及在为 Photo Show 操作呈现的视图上的图像上的链接是什么样的?
只是想知道这一切是如何结合在一起的?
这是我的照片控制器:
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
还有我的路由器:
namespace :gallery do
resources :collections, only: [:index, :show] do
resources :albums, only: [:index, :show] do
resources :photos, only: :show
end
end
end
我认为我不能使用链接助手,因为 Rails 不会;如果没有适用的路由,我不会生成一个,但我不确定如何在路由器端“插入”这个?
有什么想法吗?
【问题讨论】:
-
您介意接受我的回答,这样我的帮助就不会让我扣分吗?
标签: ruby-on-rails hyperlink controller routes action