开发者

Rails3: Expected admin/items_controller.rb to define ItemsController

The following causes unexpected exception:

Expected app/controllers/admin/items_controller.rb 
to define ItemsController

 

Foo::Application.routes.draw do
  resources :items

  match '/admin' => 'admin/overview#index', :as => :admin
  namespace :admin do
    res开发者_如何学Pythonources :items
  end
end


% cat app/controllers/admin/items_controller.rb
class Admin::ItemsController < Admin::BaseController
end

% cat app/controllers/admin/base_controller.rb
class Admin::BaseController < ActionController::Base


% cat app/controllers/items_controller.rb
class ItemsController < ApplicationController
end

It worked for me in the Rails 2.3.5.

What might be wrong the code? How can I fix that?


I can't reproduce the error this particular time, but I have run into it in the past. From memory, there are two things you can do:

  • Go to the Rails console (rails console in your application directory) and type in ItemsController. The error message, if any, should be useful.

  • One hackish fix that I've used is to load items_controller.rb before Rails start to autoload the controllers. You can either prepend the config.autoload_paths array with the path, or you can add a manual require to somewhere in your application.rb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜