使用'resources'关键字制作了哪些路线?

时间:2012-12-06 15:43:52

标签: ruby-on-rails routes

在一个类的rails应用程序上创建一个ruby,我们不允许使用resources关键字,所以我的routes文件如下所示:

School::Application.routes.draw do
  # Routes for departments
  get "depts", :to=>"depts#index"
  get "depts/new", :to=>"depts#new"                                              
  post "depts", :to=>"depts#create"
  get "depts/:id", :to=>"depts#show"
  get "depts/:id/edit", :to=>"depts#edit"
  put "depts/:id", :to=>"depts#update"
  delete "depts/:id", :to=>"depts#destroy"
end

当我尝试进入编辑页面时出现问题,因为我不知道路由的正确':as'字段,似乎无法在任何地方找到它们。有人可以告诉我,如果我使用下面这行,会是什么样的?

resource :depts

感谢。

2 个答案:

答案 0 :(得分:1)

您可以阅读路线指南

http://guides.rubyonrails.org/routing.html

如果你很懒,请按ctrl + F“资源:照片”

更新:针对:as

的关键字resources

http://guides.rubyonrails.org/routing.html#nested-names

OR

http://guides.rubyonrails.org/routing.html#overriding-the-named-helpers

更好:使用:as自定义操作

http://guides.rubyonrails.org/routing.html#naming-routes

答案 1 :(得分:0)

此外,您可以使用以下命令找到路线的方式

  rake routes

列出了所有使用http方法配置的路由

相关问题