类别/show.html.erb
<body class="home">
<% @category.subcategories.each do |subcategory| %>
<%= link_to subcategory.name, subcategory.id %>
<% end %>
在 Category#show undefined method `model_name' for Fixnum:Class 中引发 NoMethodError
网址是http://example.com:3000/category/11
路由.rb
FirstApp::Application.routes.draw do
root 'category#index'
resources :category
end
类别控制器
class CategoryController < ApplicationController
def index
@categories = Category.all
end
def new
end
def show
@category = Category.find params[:id]
end
end
子类别控制器为空
class SubcategoryController < ApplicationController
def create
end
def new
end
def show
@category = Category.find(params[:id])
end
end
方法 category.subcategories 在控制台中工作。我可能遗漏了一些明显的东西。