Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 自定义每个操作的资源路由_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 4_Routes_Custom Routes - Fatal编程技术网

Ruby on rails 自定义每个操作的资源路由

Ruby on rails 自定义每个操作的资源路由,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,routes,custom-routes,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,Routes,Custom Routes,我有一个参考资料:posts。如何将其路径自定义为以下路径,以及如何使用普通资源路径名调用它: URL Controller action Helper function 'q' 'posts#index' posts_path 'q/(:id)' 'posts#show' post_path(:id) 'ask' 'posts#new' new_post_path 'q

我有一个
参考资料:posts
。如何将其路径自定义为以下路径,以及如何使用普通资源路径名调用它:

URL          Controller action      Helper function
'q'          'posts#index'          posts_path
'q/(:id)'    'posts#show'           post_path(:id)
'ask'        'posts#new'            new_post_path
'q'          'posts#create'         posts_path
这是我尝试过的,但没有达到上面的预期效果

get 'q' => 'posts#index', as: :posts
get 'q/(:id)' => "posts#show", as: :post
get 'ask' => 'posts#new'

您可能会收到一个错误,因为您试图分配一个已在使用的路由名称


resources posts
调用将生成
posts
post
路由的定义。如果将
as:..
子句更改为引用不同的(未使用的)名称,则不会再出现该错误。

请尝试
参考资料:posts path=>q'