您好我正在 rails 4.2.5 , ruby 2.3.1p112 。
我正面临此错误,错过了所需的密钥永久链接。
错误信息是:
No route matches {:action=>"show", :controller=>"product_categories", :requirements=>{:id=>/[^.?]/}} missing required keys: [:permalink]
我的观点(错误时间)
= link_to top_level.name, product_category_path,:permalink => top_level.permalink, :title => "Shop Designer Brands in #{top_level.name}", "data-tracking-event" => "PCInHeader", "data-label" => top_level.name, :class => "gaevent"
我的路线
match "/catalog/*permalink" => "product_categories#show", :as => "product_category", :via => [:get], :requirements => { :id => /[^.?]/ }
帮我解决这个问题?
答案 0 :(得分:0)
将permalink
哈希作为参数传递给url helper
= link_to top_level.name, product_category_path(permalink: top_level.permalink), title: "Shop Designer Brands in #{top_level.name}", "data-tracking-event" => "PCInHeader", "data-label" => top_level.name, :class => "gaevent"
希望有所帮助!
答案 1 :(得分:0)
只需做product_category_path(永久链接:永久链接)因为第一个参数被视为Id,但在这里你需要永久链接而不是ID