【问题标题】:resource routes without member id没有成员 ID 的资源路由
【发布时间】:2012-06-15 01:47:22
【问题描述】:

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

Name::Application.routes.draw do
  resource :categories
end

问题是生成的url中没有member id:

$ 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(但我不知道它是否相关)。我有一个模型CategoryCategoriesController

可能是什么问题?

【问题讨论】:

    标签: ruby-on-rails rest routes


    【解决方案1】:

    最后忘了加s

    resources :categories
    

    resourcesresource 是不同的东西:resourcesresource

    【讨论】:

    • 同样,为此浪费了 15 分钟,该死的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    相关资源
    最近更新 更多