[英]Rails, get url to engine controller action by params
I have two isolated engines Offer
and Prices
. 我有两个孤立的发动机
Offer
和Prices
。
How I can get url to Prices engine controller from Offers engine view, using hash with params? 我如何从提供引擎视图获取价格引擎控制器的url,使用hash与params?
#config/routes.rb
Rails.application.routes.draw do
mount Offers::Engine, at: "offers", as: "offers_routes"
mount Prices::Engine, at: "prices", as: "prices_routes"
end
#offers/offers_controller.rb
class Offers::OffersController
def show
end
end
#prices/prices_controller.rb
class Prices::PricesController
def index
end
end
#views/offers/show.html.slim
= link_to "Prices", { action:"index", controller:"prices/prices" }
In this case link_to raise error: 在这种情况下link_to引发错误:
*** ActionController::RoutingError Exception: No route matches {:controller=>"prices/prices"}
I know about offers_routes.offers_path
helper, but in my situation I should use hash with params. 我知道
offers_routes.offers_path
助手,但在我的情况下,我应该使用hash与params。
You must pass the use_route
param if you are using engine routes. 如果使用引擎路由,则必须传递
use_route
参数。
= link_to "Prices", { action:"index", controller:"prices/prices", use_route:"prices_routes" }
Source link: https://github.com/rails/rails/blob/v3.2.13/actionpack/lib/action_dispatch/routing/route_set.rb#L442 来源链接: https : //github.com/rails/rails/blob/v3.2.13/actionpack/lib/action_dispatch/routing/route_set.rb#L442
But this is more clear solution: 但这是更明确的解决方案:
= link_to "Prices", prices_routes.url_for(action:"index", controller:"prices/prices")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.