Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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 我可以在RubyonRails应用程序中通过带有排除项的资源方法设置路由吗?_Ruby On Rails_Routes - Fatal编程技术网

Ruby on rails 我可以在RubyonRails应用程序中通过带有排除项的资源方法设置路由吗?

Ruby on rails 我可以在RubyonRails应用程序中通过带有排除项的资源方法设置路由吗?,ruby-on-rails,routes,Ruby On Rails,Routes,说我会写 资源:照片 在routes.rb中 这将创建路由: HTTP Verb Path Controller#Action Used for GET /photos photos#index display a list of all photos GET /photos/new photos#new return an HTML form for

说我会写

资源:照片
routes.rb中

这将创建路由:

HTTP Verb Path Controller#Action Used for GET /photos photos#index display a list of all photos GET /photos/new photos#new return an HTML form for creating a new photo POST /photos photos#create create a new photo GET /photos/:id photos#show display a specific photo GET /photos/:id/edit photos#edit return an HTML form for editing a photo PATCH/PUT /photos/:id photos#update update a specific photo DELETE /photos/:id photos#destroy delete a specific photo 要获取除编辑和更新之外的所有路由,请执行以下操作:

GET /photos photos#index display a list of all photos GET /photos/new photos#new return an HTML form for creating a new photo POST /photos photos#create create a new photo GET /photos/:id photos#show display a specific photo DELETE /photos/:id photos#destroy delete a specific photo 获取/照片照片#索引显示所有照片的列表 GET/photos/new photos#new返回用于创建新照片的HTML表单 发布/照片照片#创建新照片 GET/photos/:id photos#显示特定的照片 删除/photos/:id photos#销毁删除特定照片 或者我只能手动写入每个路由以获得预期结果?

是的,您可以

您可以执行以下操作:

resources :photos, only: [:index, :new, :create, :show, :destroy]
或者,如果您愿意:

resources :photos, except: [:edit, :update]
请在此处阅读更多信息:

是的,您可以

您可以执行以下操作:

resources :photos, only: [:index, :new, :create, :show, :destroy]
或者,如果您愿意:

resources :photos, except: [:edit, :update]
请在此处阅读更多信息:

您可以试试这个

:except
选项指定Rails不应创建的路由或路由列表:

resources :photos, except: [:edit, :update]
欲了解更多信息,请点击此处 你可以试试这个

:except
选项指定Rails不应创建的路由或路由列表:

resources :photos, except: [:edit, :update]
欲了解更多信息,请点击此处

除了我写完这篇文章后肯定会在这里出现的三个答案之外,我建议你通读,这是一篇关于这个主题的很好的介绍(顺便说一下,其他指南也是)。除了我写完这篇文章后肯定会在这里出现的三个答案之外,我建议你通读,这是一个很好的主题介绍(顺便说一下,其他指南也是如此)。