title: rails 3.1 dynamic controller instantiation
body: <p>I have a Rails Engine gem in which I want to load a HomeController class definition dynamically from an initializer. I can instantiate the class correctly, but when I go to call the index action, I get this error :</p>
  
  <pre><code>TypeError in HomeController#index
  
  can't convert nil into String
  Rails.root: /home/chris/test_app
  
  Full Trace:
  actionpack (3.1.0) lib/action_view/template/resolver.rb:16:in `&lt;&lt;'
  actionpack (3.1.0) lib/action_view/template/resolver.rb:16:in `build'
  actionpack (3.1.0) lib/action_view/template/resolver.rb:127:in `find_templates'
  actionpack (3.1.0) lib/action_view/template/resolver.rb:45:in `find_all'
  actionpack (3.1.0) lib/action_view/template/resolver.rb:76:in `cached'
  actionpack (3.1.0) lib/action_view/template/resolver.rb:44:in `find_all'
  actionpack (3.1.0) lib/action_view/path_set.rb:21:in `find_all'
  actionpack (3.1.0) lib/action_view/path_set.rb:20:in `each'
  actionpack (3.1.0) lib/action_view/path_set.rb:20:in `find_all'
  actionpack (3.1.0) lib/action_view/path_set.rb:19:in `each'
  actionpack (3.1.0) lib/action_view/path_set.rb:19:in `find_all'
  actionpack (3.1.0) lib/action_view/path_set.rb:29:in `exists?'
  actionpack (3.1.0) lib/action_view/lookup_context.rb:94:in `template_exists?'
  </code></pre>
  
  <p>I cut the trace off after the actionpack part because it was really long, but I think this is all the relevant information. </p>
  
  <p>Here is my Engine class definition:</p>
  
  <pre><code>module MyGem
     class Engine &lt; Rails::Engine
  
        initializer 'my_gem.load_middleware' do |app|
          home_controller = create_controller 'HomeController'
        end
  
        def create_controller(class_name, &amp;block)
          klass = Class.new ApplicationController, &amp;block
          Object.const_set class_name, klass
          return klass
        end
     end
  end
  </code></pre>
  
  <p>this is when i have the root path set to home#index . if I create a home_controller.rb in app/controllers in either the application or the gem like so:</p>
  
  <pre><code>class HomeController &lt; ApplicationController
  end
  </code></pre>
  
  <p>then everything works fine and the index action is rendered appropriately, so I'm sure there is no problem with my routes, views, or application controller.</p>
  
  <p>Any light shed on this issue would be much appreciated.
  <em>edit</em>
  the output of </p>
  
  <p><code>HomeController.view_paths.join " : "</code> </p>
  
  <p>is</p>
  
  <p><code>/home/chris/gems/my_gem/app/views : /home/chris/test_app/app/views</code></p>