0

我们正在 spec/dummy 下测试 customerx 引擎。引擎customerx的索引页可以正常显示。链接在这里:

<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

在引擎 customerx 的 routes.rb 中,资源声明为:

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

编辑/索引没有路由错误。新/创建所有通行证的 rspec 案例。问题似乎是没有找到new的动作(删除new和create的def后错误是一样的)。

导致错误的代码可能有什么问题?感谢帮助。

4

1 回答 1

0

get "customer_status_categories/new"该问题已通过在 routes.rb 中为引擎 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

在创建新控制器时,自动get ...new插入了 routes.rb 。rails generate我们不知道为什么这条线会导致uninitialized constant错误(但不是其他的,例如索引和编辑)。有人可以阐明问题的原因吗?

于 2013-01-11T17:23:19.887 回答