我在routes.rb
中有这个自定义路线match '/businesses/:permalink', :to => 'businesses#show', :as => :business_permalink
resources :businesses
我构建了一个这样的链接:
<%= link_to business.name, business_permalink_path %>
但是,每当我访问带有该链接的页面时,都会收到此错误:
No route matches {:controller=>"businesses", :action=>"show"}
我尝试反转路线顺序:
resources :businesses
match '/businesses/:permalink', :to => 'businesses#show', :as => :business_permalink
这不起作用。如果我将链接更改为:
,它会起作用show action存在并在文件controllers / business_controller.rb中定义。我想使用永久链接创建自定义URL。
我是Rails的新手,我知道我只是遗漏了一些东西。我错过了什么?
答案 0 :(得分:5)
试试这个:
<%= link_to business.name, business_permalink_path(business.permalink) %>
答案 1 :(得分:-1)
试试这个:
match '/businesses/:permalink' => 'businesses#show', :as => :business_permalink