【问题标题】:No route matches {:action=>"index", :controller=>"categories"}没有路线匹配 {:action=>"index", :controller=>"categories"}
【发布时间】:2014-11-04 13:41:18
【问题描述】:

我坚持将所有类别存储到数据库中的一个实例中。

以下是说明: 在 categories_controller.rb 中,在 def index 下,为类别编写索引方法的主体。 请记住密切关注示例并以 end 结束。点击运行。

这是我的代码:

class CategoriesController < ApplicationController

  def index
    @categories = Category.all
  end

  def show
  end

  def new
  end

  def edit
  end

  def delete
  end

  private 
  def category_params
    params.require(:category).permit(:name, :thumburl)
  end
end

我做错了什么?

【问题讨论】:

  • Marek Lipka 的回答是正确的。此外,如果您打算仅依靠 resources :categories 为您创建 CRUD 方法,请确保将方法名称 delete 更改为 destroy

标签: ruby-on-rails indexing


【解决方案1】:

你应该把它添加到config/routes.rb:

resources :categories

我还建议学习一些 Rails 基础知识。

【讨论】:

  • @user3818274 我的回答有帮助吗?
  • 是的,但是本教程在 codecademy 中,所以他们没有向我显示 config/routes.rb 文件,所以我无法添加资源
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 2013-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多