Ruby on rails Rails链接_以生成带有子目录的URL
在我的routes文件中,我有一行:Ruby on rails Rails链接_以生成带有子目录的URL,ruby-on-rails,ruby-on-rails-3,actionview,Ruby On Rails,Ruby On Rails 3,Actionview,在我的routes文件中,我有一行: match 'documents/:category/:id' => 'documents#show' 允许我使用URL,如: *本地主机:3000/文档/课程计划/天\u 01* URL工作正常,但我不知道如何使用link\u to生成它 返回错误: 没有路由匹配{:action=>“show”,:controller=>“documents”, :id=>“/lesson\u plans/day\u 01”} 工作正常,但会生成URL: lo
match 'documents/:category/:id' => 'documents#show'
允许我使用URL,如:
*本地主机:3000/文档/课程计划/天\u 01*
URL工作正常,但我不知道如何使用link\u to生成它
返回错误: 没有路由匹配{:action=>“show”,:controller=>“documents”, :id=>“/lesson\u plans/day\u 01”}
工作正常,但会生成URL: localhost:3000/文档/天\u 01?类别=课程计划 还不够干净
是否有生成URL的方法: localhost:3000/文档/课程计划/天\u 01
:文档,:action=>:show,:category=>“课程计划”,:id=>“day\u 01”}%>
尝试一下:
match 'documents/:category/:id' => 'documents#show', :as => :document
及
它应产生:
http://localhost:3000/documents/lesson_plans/day_01
<%= link_to "day_01", {:controller => :documents, :action => :show, :category => "lesson_plans", :id => "day_01"} %>
match 'documents/:category/:id' => 'documents#show', :as => :document
= link_to 'day_01', document_path('day_01', :category => 'lesson_plans')
http://localhost:3000/documents/lesson_plans/day_01