作为第一次使用Rails的用户,我不得不说我喜欢Rails的做事方式。但是,我正在尝试创建一个简单的表单。我收到以下错误:
undefined method `categories_path' for #<#<Class:0x007f0440365880>:0x007f0430256cd8>
我尝试在控制器中创建一个categories_path
方法(虽然我不确定它会用于什么),但这并没有解决错误。那里的铁路专家知道发生了什么事吗?
以下是相关代码:
视图/类别/ new.html.erb
<%= form_for @category do |f| %>
<%= f.label :category %>
<%= f.text_field :name %><br />
<%= f.submit %>
<% end %>
的routes.rb
Jackeyes::Application.routes.draw do
scope "/admin" do
resources :product, :category
end
end
category_controller.rb
class CategoryController < ApplicationController
def index
@category = Category.all
end
def new
@category = Category.new
end
def create
@category = Category.new(params[:category])
@category.save
end
end
答案 0 :(得分:5)
使您的资源成为多元化:
resources :products, :categories
再试一次。