title: Creating a Ruby on Rails 3 gem with a generator (incl. namespace)
body: <p>I am trying to create a gem with a generator for Rails 3 (beta 4). I followed <a href="http://www.railsdispatch.com/posts/how-rails-3-enables-more-choices-part-1" rel="noreferrer">these instructions</a>, and but I couldn't get it running. The problem is that when I am defining a module in the generator file, the generator gets listed with 'rails generate', but can't get executed because the generator isn't found.</p>
  
  <p>From the instructions (doesn't work with 'rails generate my_gem:install'):</p>
  
  <pre><code>module MyGem
    class InstallGenerator &lt; Rails::Generators::Base
      source_root File.expand_path("../templates", __FILE__)
  
      # all public methods in here will be run in order
      def add_my_initializer
        template "initializer.rb", "config/initializers/my_gem_initializer.rb"
      end
    end
  end
  </code></pre>
  
  <p>Modified (works with 'rails generate install):</p>
  
  <pre><code>class InstallGenerator &lt; Rails::Generators::Base
    source_root File.expand_path("../templates", __FILE__)
  
    # all public methods in here will be run in order
    def add_my_initializer
      template "initializer.rb", "config/initializers/my_gem_initializer.rb"
    end
  end
  </code></pre>
  
  <p>However, I want to have namespaces for the generator, e.g. company:gem_name:generator, for which I have to use the module approach (I think). My guess is that it has something to do with the lookup and the directory structure, but I couldn't figure out how. I tried a couple of approaches:</p>
  
  <pre><code>lib
  -generators
  --my_gem.rb
  
  lib
  -generators
  --company
  ---my_gem.rb
  
  lib
  -generators
  --company
  ---my_gem_name
  ----my_gem.rb
  </code></pre>
  
  <p>but nothing helped. I also found quite a bit on the Internet, but non if showed what I needed.</p>