所以我正在做一个项目,我想创建新的子类别。该链接有效,但我没有收到以下错误:
没有路线匹配 {:action=>"show", :controller=>"subcategories"}
该项目相当新,所以我的路线文件非常简单:
Mrprice::Application.routes.draw do
get "admin/index" => 'admin#index'
resources :products
resources :subcategories
resources :categories
root to: 'store#index', as: 'root'
end
在我看来:
<%= link_to 'New Subcategory', new_subcategory_path %>
我确定某处有错字,否则解决方案非常简单,但我一生都无法弄清楚。我希望我已经提供了足够的信息,并且这里有人知道问题所在!
编辑:subcategories_controller.rb(相关方法)
def show
@subcategory = Subcategory.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @subcategory }
end
end
def new
@subcategory = Subcategory.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @subcategory }
end
end
def create
@subcategory = Subcategory.new(params[:subcategory])
respond_to do |format|
if @subcategory.save
format.html { redirect_to @subcategory, notice: 'Subcategory was successfully created.' }
format.json { render json: @subcategory, status: :created, location: @subcategory }
else
format.html { render action: "new" }
format.json { render json: @subcategory.errors, status: :unprocessable_entity }
end
end
end
耙路线给出:
admin_index GET /admin/index(.:format) admin#index
products GET /products(.:format) products#index
POST /products(.:format) products#create
new_product GET /products/new(.:format) products#new
edit_product GET /products/:id/edit(.:format) products#edit
product GET /products/:id(.:format) products#show
PUT /products/:id(.:format) products#update
DELETE /products/:id(.:format) products#destroy
subcategories GET /subcategories(.:format) subcategories#index
POST /subcategories(.:format) subcategories#creat
new_subcategory GET /subcategories/new(.:format) subcategories#new
edit_subcategory GET /subcategories/:id/edit(.:format) subcategories#edit
subcategory GET /subcategories/:id(.:format) subcategories#show
PUT /subcategories/:id(.:format) subcategories#updat
DELETE /subcategories/:id(.:format) subcategories#destr
categories GET /categories(.:format) categories#index
POST /categories(.:format) categories#create
new_category GET /categories/new(.:format) categories#new
edit_category GET /categories/:id/edit(.:format) categories#edit
category GET /categories/:id(.:format) categories#show
PUT /categories/:id(.:format) categories#update
DELETE /categories/:id(.:format) categories#destroy
root / store#index
注意:不确定如何修复格式 - 我已经尝试过代码块