0

We are testing a customerx engine under spec/dummy. Index page of the engine customerx can be displayed without any error. Here is the link:

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

However there is routing error uninitialized constant CustomerStatusCategoriesController for new customer link as below:

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

The rake routes does show the right new customer route:

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

In routes.rb for engine customerx, the resources is declared as:

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

There is no routing error with edit/index. The rspec cases for new/create all passes. The problem seems that the action for new is not found (the error is the same after deleting def of new and create).

What could be wrong in code causing the error? Thanks for help.

user938363
  • 9,990
  • 38
  • 137
  • 303

1 Answers1

0

The problem was solved by commenting out get "customer_status_categories/new" in routes.rb for engine customerx:

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

The get ...new in routes.rb was inserted by rails generate automatically when creating new controller. We don't know why this line causes uninitialized constant error (but not on others such as index and edit). Can Someone shed the light on the cause of the issue?

user938363
  • 9,990
  • 38
  • 137
  • 303