【发布时间】:2014-03-14 18:36:41
【问题描述】:
我正在使用 Gretel gem 将面包屑路径添加到我自定义构建的照片库中。
画廊模型之间的关系是:
收藏:
has_many :children, class_name: "Collection", foreign_key: "parent_id"
belongs_to :parent, class_name: "Collection", foreign_key: "parent_id"
has_many :albums
专辑:
has_many :photos, :dependent => :destroy
belongs_to :collection
然后我将一些 Gretel crumbs 定义为:
crumb :collection do |collection|
link collection.title, gallery_collection_path(collection)
if collection.parent
parent :collection, collection.parent
else
parent :gallery
end
end
crumb :albums do |parent_collection|
link parent_collection.title, gallery_collection_albums_path(parent_collection, :albums)
parent :collection, parent_collection
end
但在导航时,我会得到一条类似我到达相册后的轨迹:
主页 › 图库 › Days out › 主题公园 › 奥尔顿塔 › 奥尔顿塔
第一个“奥尔顿塔”的网址是
/collections/617
第二个是:
/collections/617/相册
我认为与我的 Collections 控制器有关的事情搞砸了,因为如果集合没有子集,我的 Collections Show 操作将重定向到我的 Albums Index 操作(因此需要显示专辑列表)
集合控制器是:
def index
@size = :medium
@title = 'Gallery'
@collections = Collection.roots
end
def show
@collection = Collection.find_by_id(params[:id])
if @collection.has_children?
@collections = @collection.children
@size = :medium
@title = @collection.title
else
redirect_to [:gallery, @collection, :albums]
end
end
关于如何解决此问题以便在查看我的专辑索引页面时获得以下所需输出的任何想法?:
主页 › 图库 › Days out › 主题公园 › 奥尔顿塔
【问题讨论】:
标签: ruby-on-rails relationship breadcrumbs