加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 没有成员编号的资源路由

发布时间:2020-12-16 20:06:56 所属栏目:百科 来源:网络整理
导读:我开发了一个Rails应用程序,我添加了简单的路由: Name::Application.routes.draw do resource :categoriesend 问题是生成的URL中没有成员编号: $rake routescategories POST /categories(.:format) categories#createnew_categories GET /categories/new(.
我开发了一个Rails应用程序,我添加了简单的路由:
Name::Application.routes.draw do
  resource :categories
end

问题是生成的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

我使用Rails 3.2.3.我不在应用程序中使用ActiveRecord(但我不知道它是否相关).我有一个模型类别和CategoriesController.

可能是什么问题?

解决方法

你忘了添加到最后:
resources :categories

资源和资源是不同的:resources和resource.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读