Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails链接_以生成带有子目录的URL_Ruby On Rails_Ruby On Rails 3_Actionview - Fatal编程技术网

Ruby on rails Rails链接_以生成带有子目录的URL

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

在我的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:

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