【问题标题】:Path helper for rails route, with param that mounts an enginerails 路线的路径助手,带有安装引擎的参数
【发布时间】:2013-01-13 21:25:15
【问题描述】:

您好,我有以下路线:

mount Spree::Core::Engine, :at => ':city_name/', :as => :spree

产生像/munich/path/in/engine/new_york/path/in/engine这样的网址

如何使用 url helper 生成这样的 url,修改城市并使用引擎的 url helper?如果引擎会为产品提供 url 助手(例如product_path(@product)),是否有类似

spree_path(:city_name => "munich").product_path(@product)

生成一个类似/munich/products/1的网址?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 spree


    【解决方案1】:

    这应该可以工作,使用:

    spree.product_path(@product, :city_name => "munich")
    

    【讨论】:

    【解决方案2】:

    正确的做法是使用Engine自带的url helpers:

    Spree::Core::Engine.routes.url_helpers.product_path
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多