Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Engines are awesome!! Definitely look at the link Jamie provided in his answer..it is a good starting point. Engines are the way to go with Rails 3. I feel that it is one of the most powerful features of the framework, and I converted almost every piece of common functionality in my apps into engines. IT saves you a ton of time if you are creating alot of apps. Here is my current workflow when creating engines: </p> <p><strong>Step 1:</strong> <code>gem install jeweler</code> if you dont have it. Then create a blank gem using jeweler.</p> <p><strong>Step 2:</strong> update the Rakefile provided by jeweler with your gem info and any dependencies. You may need to add a filelist so the gemspec can point to the correct files, and exlude any files you dont want when you build it.</p> <pre><code>gem.files = FileList['lib/**/*.rb','[A-Z]*', 'lib/**/**/*'].to_a </code></pre> <p><strong>Step 3:</strong> Add your Rails application structure - app/controllers, app/views, etc.. to the top-level directory in the gem. You can also include /config directory for your routes.rb which will be appended to your main apps routes.</p> <p><strong>Step 4:</strong> Set up your lib directory like this:</p> <blockquote> <p>/lib/your_engine_name.rb (require engine.rb in this file and any other files in lib that you need) /lib/your_engine_name/<br> /lib/your_engine_name/engine.rb</p> </blockquote> <p><strong>Step 5:</strong> Add code to engine.rb:</p> <pre><code> require 'your_engine_name' require 'rails' module YourEngineName class Engine &lt; Rails::Engine #load rake tasks go here #initializers go here end end </code></pre> <p><strong>Step 6:</strong> Add all your custom engine code to app/* and lib/your_engine_name/</p> <p><strong>Step 7:</strong> Build the gem using "rake build". You must do this so Bundler can see your files in the gemspec (which is generated when you build) in step #8</p> <p><strong>Step 8:</strong> For local testing reference the local path in the Gemfile of your main application where you want to include the engine:</p> <pre><code>#Gemfile gem "your_engine_name", :require =&gt; "your_engine_name", :path =&gt; "/your_engines/your_engine_name" </code></pre> <p><strong>Step 9:</strong> bundle install and start up your local app server.</p> <p><strong>Step 10:</strong> Since you are referencing the local path, you can make changes to the gem and see them in your main app without rebuilding (unless you need to add new files to the gemspec)</p> <p><strong>Step 11:</strong> put your gem source on github so you can use it in prod. Make use of jewelers versioning rake tasks. I combine some of the rake tasks like this in order to do the git push and tag in the same step and include them in the engine's Rakefile:</p> <pre><code>namespace :version do desc "create a new version, create tag and push to github" task :github_and_tag do Rake::Task['github:release'].invoke Rake::Task['git:release'].invoke end desc "bump patch push to github" task :patch_release do Rake::Task['version:bump:patch'].invoke Rake::Task['version:github_and_tag'].invoke end desc "bump minor push to github" task :minor_release do Rake::Task['version:bump:minor'].invoke Rake::Task['version:github_and_tag'].invoke end desc "bump major push to github" task :major_release do Rake::Task['version:bump:major'].invoke Rake::Task['version:github_and_tag'].invoke end end </code></pre> <p><strong>Step 12:</strong> When deploying to production, change the source in the Gemfile to github and reference a version tag:</p> <pre><code>gem 'your_engine_name', :git =&gt; 'git@github.com:yourusername/your_engine_name.git', :tag=&gt;"v1.1.1" </code></pre> <p>I am using this hack to reference 2 gem sources in Gemfile until they add that feature to Bundler: <a href="http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/" rel="nofollow noreferrer">http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/</a></p> <p>Let me know if you have any problems with this. I am working on a blog post to show this in more detail and I may have left out a few things.. just writing this off the top of my head right now..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload