没有成员标识的资源路由

mrz*_*asa 16 rest routes ruby-on-rails

我开发了一个Rails应用程序,并添加了简单的路由:

Name::Application.routes.draw do
  resource :categories
end
Run Code Online (Sandbox Code Playgroud)

问题是生成的URL中没有成员标识:

$ rake routes
categories      POST   /categories(.:format)      categories#create
new_categories  GET    /categories/new(.:format)  categories#new
edit_categories GET    /categories/edit(.:format) categories#edit
                GET    /categories(.:format)      categories#show
                PUT    /categories(.:format)      categories#update
                DELETE /categories(.:format)      categories#destroy
Run Code Online (Sandbox Code Playgroud)

我使用Rails 3.2.3.我不在应用程序中使用ActiveRecord(但我不知道它是否相关).我有一个模特CategoryCategoriesController.

可能是什么问题?

Mik*_*Mik 31

你忘了添加s到最后:

resources :categories
Run Code Online (Sandbox Code Playgroud)

resources并且resource是不同的东西:资源资源.

  • 同样,在这上面失去了15分钟,该死的. (2认同)