title: How to run a Rails application within a gem?
body: <p>I'm not sure if this sort of thing is very common, but I keep finding myself trying to create gems that are just wrappers around a Rails application.</p>
  
  <p>My gem will have a generator to create a <code>config.ru</code> but the Rails application will live inside the gem's lib directory. I need to know how to "embed" a Rails application and configure it so that it can be run inside the gem.</p>
  
  <p>For example:</p>
  
  <pre><code>$ mygem new project
  
  mygem created a directory called "project" with the following files:
  
  project/config.ru
  project/widgets/
  project/foobars/
  </code></pre>
  
  <p>My gem will also generate some directories that will need to be added to Rails somehow so that I can access the code in those directories from the Rails app living inside the Gem.</p>
  
  <p>Any help or advice you can give me would be appreciated.</p>
  
  <p>To clarify, I'm not trying to create a Rails engine, or plugin to a Rails application. I'm trying to create a fully-fledged Rails application, but package it as a gem so that a user of my gem can run the gem (the rails app) without needing to know that it's using Rails behind the scenes.</p>
  
  <p><strong>Update:</strong> Okay, I've got a little bit working now. I've created the gem and generated the rails project inside the gem's lib directory.</p>
  
  <pre><code>$ bundle gem my_gem &amp;&amp; cd my_gem/lib
  $ rails new my_gem --skip-bundle
  </code></pre>
  
  <p>Which leaves me with:</p>
  
  <pre><code>my_gem/
    my_gem.gemspec
    bin/my_gem
    lib/
      my_gem.rb
      my_gem/
        version.rb # generated by bundler
        # the rails app:
        app/
        config/
        Gemfile
        ...etc
  </code></pre>
  
  <p>Since this gem requires Rails, I started adding the gems defined in the Rails Gemfile as dependencies in the gem's Gemspec, but I'm a little confused as to how to handle the <code>assets</code> group in the Gemfile.</p>
  
  <pre><code># Rails Gemfile
  group :assets do
    gem 'sass-rails',   '~&gt; 3.2.3'
    gem 'coffee-rails', '~&gt; 3.2.1'
    gem 'therubyracer', :platforms =&gt; :ruby
    gem 'uglifier', '&gt;= 1.0.3'
  end
  
  # gemspec
  Gem::Specification.new do |gem|
    gem.name          = "my_gem"
    # ...
    gem.add_dependency 'rails', '3.2.8'
    gem.add_dependency 'sqlite3'
    gem.add_dependency 'jquery-rails'
    # how to add the assets group gems?
  end
  </code></pre>