2013-08-30 32 views
0

所以我正在一個項目上工作,我想創建新的子類別。鏈接是工作,但我沒有收到以下錯誤:Ruby On Rails路由錯誤(以前工作)

No route matches {: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 

注:不知道如何修正格式 - 我已經嘗試了代碼塊

+1

您遇到顯示路徑問題,您缺少某處的id – apneadiving

+0

顯示錯誤指向的文件的內容。 –

+0

我真的不明白爲什麼顯示路徑在嘗試創建新的子類別時發生錯誤。我認爲無處不在,我要表演。也沒有任何ID,因爲該項目是新的,我還沒有創建任何子類別。 – SoSimple

回答

0

好吧,我終於明白了!

問題是新子類別表單上的路由錯誤。 我:

<%= link_to "Subcategories Home", subcategories_index_path %> 

我知道這是不正確的,所以我把它改爲:

<%= link_to "Subcategories Home", subcategories_url %> 

主要是我剛剛經歷Rails Routing from the Outside In去用細齒梳,直到我想通了正確的方法迴路由到子類別#索引。