2013-01-10 50 views
0

我們正在測試spec/dummy下的customerx引擎。引擎customerx的索引頁面可以無任何錯誤地顯示。這裏是鏈接:控制器無法看到def new/create for rails 3.2.8引擎

<li><%= link_to 'Customers', customerx.customer_status_categories_path %></li> 

但是有路由錯誤uninitialized constant CustomerStatusCategoriesController新的客戶鏈接如下:

<li><%= link_to 'New Customer', customerx.new_customer_status_category_path %></li> 

rake routes確實顯示正確的新顧客路線:

Routes for Customerx::Engine: 
customer_status_categories_index GET /customer_status_categories/index(.:format) customer_status_categories#index 
    customer_status_categories_new GET /customer_status_categories/new(.:format)  customer_status_categories#new 
customer_status_categories_create GET /customer_status_categories/create(.:format) customer_status_categories#create 
    customer_status_categories_edit GET /customer_status_categories/edit(.:format)  customer_status_categories#edit 
customer_status_categories_update GET /customer_status_categories/update(.:format) customer_status_categories#update 
     customer_status_categories GET /customer_status_categories(.:format)   customerx/customer_status_categories#index 
            POST /customer_status_categories(.:format)   customerx/customer_status_categories#create 
    new_customer_status_category GET /customer_status_categories/new(.:format)  customerx/customer_status_categories#new 
    edit_customer_status_category GET /customer_status_categories/:id/edit(.:format) customerx/customer_status_categories#edit 
     customer_status_category PUT /customer_status_categories/:id(.:format)  customerx/customer_status_categories#update 

在routes.rb爲引擎customerx,資源聲明爲:

resources :customer_status_categories, :only => [:index, :new, :create, :edit, :update] 

編輯/索引沒有路由錯誤。新建/創建所有通行證的rspec情況。這個問題似乎沒有找到新的動作(在刪除新的和創建的def後,錯誤是相同的)。

導致錯誤的代碼有什麼錯誤?感謝幫助。

回答

0

問題解決了在routes.rb中註釋掉get "customer_status_categories/new"發動機customerx:在routes.rb中

Customerx::Engine.routes.draw do 
    get "customer_status_categories/index" 

    #get "customer_status_categories/new" 

    get "customer_status_categories/create" 

    get "customer_status_categories/edit" 

    get "customer_status_categories/update" 

    resources :customer_status_categories 

    root :to => 'customer_status_categories#index' 

end 

get ...newrails generate創造新的控制器時自動插入。我們不知道爲什麼這行會導致uninitialized constant錯誤(但不會在其他上如索引和編輯)。有人可以闡明問題的原因嗎?