【问题标题】:How to use breadcrumbs_on_rails with 2 parameters in a route如何在路线中使用带有 2 个参数的面包屑_on_rails
【发布时间】:2014-09-29 17:59:48
【问题描述】:

我使用 breadcrumbs_on_rails gem。它适用于“经典”路线。

但是,我遇到了这条路径的问题:

get '/:category_id/:id', :controller => "contents", :action => "show", :as => :category_content

add_breadcrumb @content.category.label, :category_path 生成的链接位于 category_id 而不是(内容对象的)id。

感谢提前

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 breadcrumbs


    【解决方案1】:

    我解决了我的问题...

    我使用:add_breadcrumb @content.category.label, @content.category

    【讨论】:

    • 你根本没有使用路径?
    【解决方案2】:

    根据the docs,传递给add_breadcrumb的路径可以是符号、proc或字符串。

    普通路径助手渲染成一个字符串,所以你应该能够像这样指定你的路径:

    add_breadcrumb @content.category.label, category_content_path(:category_id => @content.category.id, :id => @content.id)
    

    【讨论】:

    • 它对我不起作用,但我找到了另一个解决方案“add_breadcrumb @content.category.label, @content.category”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多