控制器无法看到def new / create for rails 3.2.8引擎

时间:2013-01-10 17:37:40

标签: ruby-on-rails-3 rails-engines

我们正在测试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

在engine customerr的routes.rb中,资源声明为:

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

编辑/索引没有路由错误。新的/创建所有传递的rspec案例。问题似乎是找不到new的操作(删除def和创建后的错误是相同的。)

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

1 个答案:

答案 0 :(得分:0)

通过在routes.rb中为引擎customerx注释掉get "customer_status_categories/new"来解决问题:

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错误(但不会导致其他错误,例如索引和编辑)。有人能否解释问题的原因?