Dr Nic

RailsRally 2007 and GemsOnRails

In the past there has been RailsDay, but now the locals of Brazil are running a week-long competition – RailsRally.

The organiser, Ronie Uliana, There are some interesting rules for others who might want to run a RailsRally for people outside of Brazil:

  • Teams of any size – you just have to figure out how you’re going to split the prizes!
  • Competition runs for 7 days
  • To prevent you pre-writing your application, there will be a theme for all applications, announced at the start of the competition.
  • No external gems allowed. I thought this was a harsh limitation, but Ronie said they will support the native-compiled gems like Hpricot and RMagik, and other gems could be frozen into your application code base with Gems on Rails [summary below].

Gems on Rails

This Rails plugin allows you to freeze or link a gem into your rails source (inspired by Rick Olsen’s gems plugin)


To install the plugin:

> gem install gemsonrails
> cd rails-app-folder
> gemsonrails


rake gems:freeze   GEM=gem_to_freeze
rake gems:link     GEM=gem_to_link
rake gems:unfreeze GEM=gem_to_unfreeze_or_unlink

The gems are loaded into vendor/gems and are loaded automatically. Any rake task files from the gems are also automatically loaded via your root Rakefile (that is, if you type rake -T from your application path the rake files in your gems are included; very nifty)
This plugin is experimental, and will invoke an init.rb file in the root of the gem if it has one, else it just adds the gem into the LOAD_PATH, and you’ll need to require it as per normal.

If the target gem doesn’t have an init.rb, you can create one in the vendor/gems/<gem-name>/ folder to do any preloading you’d like; instead of doing it in environment.rb.

This plugin was written by moi, and is used in a production environment, but still proceed with caution and ping me with any quirks or features.

Related posts:

  1. Where art thou generator? Summary: click to select UPDATE: Rails Generators within RubyGems support...

23 Responses to “RailsRally 2007 and GemsOnRails”

  1. Matt Parrish says:

    This plugin (and Rick Olsen’s) doesn’t seem to work with rubygems 0.9.2 and windows. I get the following error:

    install directory “ruby-net-ldap-0.0.4″ not absolute

    when running

    rake gems:freeze GEM=ruby-net-ldap

    Any ideas?

  2. Dr Nic says:

    Looks like a known bug in RubyGems 0.9.X (see the bottom of https://rubyforge.org/tracker/index.php?func=detail&aid=7980&group_id=126&atid=575).

    New Release – 0.4.3 – bypasses this RubyGems bug by passing the absolute path.

    gem install gemsonrails
    cd app-folder
    rake gems:freeze GEM=ruby-net-ldap
  3. Jason says:

    gemsonrails doesn’t seem to handle the case where one gem’s name is a subset of another. I can’t freeze the ruby-debug gem while I have the ruby-debug-base gem (a dependency of ruby-debug) installed. Perhaps I’m off my rocker, if so please let me know how to make it work without installing ruby-debug-base.


  4. [...] Dr Nic a fait d’autres plugins intéressants, dont Gems on Rails, qui permet de figer avec une application une version des plugins utilisés dans le cadre de celle-ci. [...]

  5. Glenn Rempe says:

    Hi Dr. Nic,

    First, I love the idea of this gem. Thanks for doing your magic on it. I am just starting out using it and have a few feature requests if you don’t mind… :-)

    - Since you say we need to require manually any gems without an init.rb, can you alert us at the time of freezing if a particular gem does not have one? Can you add the require statement for us? :-)

    - Can you add a rake task like gems:list_unfrozen which will check for gems installed locally which have NOT been frozen into my local app.

    - Can you add a rake task like gems:list_unfrozen:newer which would check for locally installed gems which may be newer than the ones I currently have frozen in my app? Another rake task that would then auto freeze each of those newer gems, replacing the ones I have frozen currently would be icing on the gem.

    - Can you add a rake task like gems:freeze:all which would freeze all of my locally installed gems in one fell swoop into the current rails app? Would naturally want something like gems:unfreeze:all to counter that.

    - Could the app warn me if I am freezing a local gem that has dependencies, which are not yet frozen? No sense freezing a particular gem if it won’t work on the destination since it doesn’t have its needed gem dependencies…

    - Do I need to be warned if a gem I am freezing has compiled code in it (mysql comes to mind). What happens in that case if I then deploy my app to a remote server of a different architecture? I have not tested this yet myself.

    I just love the idea of being able to freeze my rails, and all my gems into an app and knowing that I don’t have to install all of that stuff on remote machines that I deploy to with capistrano. I would gladly trade a minute more of deploy time for knowing that my app will work.

    Thanks again for all you are adding to the rails community.

  6. Glenn Rempe says:

    Oh, and one more request to add to my previous list if I may…

    Is it possible to determine what gems that MY current rails app actually uses and depends on (and then the gems that each of those depend on) and freeze only that set for me?

    For example, it would be most excellent if I could run that task and then freeze only those 5 gems (and the 3 that they depend on to run), out of the fifty I might have installed, that my current rails app depends on. Otherwise its a bit of guesswork of course.

    Thanks for listening… :-)

  7. Dr Nic says:

    @Glenn – They are awesome questions. I haven’t hacked at gemsonrails for so long its not even checked out on my new mac :) (I just realised)

    Any chance you want to hack some of these ideas yourself, and I’ll patch them in?

    I definitely want a default require line in the init.rb file. I keep copy+pasting it from other frozen gems. So definitely need that.

  8. Dr Nic says:

    @everyone – Ok, I’ve created 0.5.0 that includes the init.rb idea + refactored the gem to use newgem/hoe. So now it has a spiffy website – http://gemsonrails.rubyforge.org

  9. mankytongue says:


    I was wondering… I’m using GemsOnRails to add gems to a small rails project, the unpacking went well, all the files are where they should be but Mongrel fails to start. It just throws an error because it isn’t able to find the requisite Gem.

    I’ve figured out the problem, the Gem that needs to be loaded is required by a plugin that gets loaded before GemsOnRails plugin (I’m assuming the plugins are loaded in alphabetical order).

    Now it would be easy to just put a little “require” in somewhere so it gets loaded before any of the plugins, but it seems a little too “hack-ish”.

    Any thoughts?


  10. Dr Nic says:

    @mankytongue – in /vendor/plugins try renaming gemsonrails to aaa_gemsonrails. Its this plugin that triggers the loading of all the vendor/gems; so making it the first plugin loaded should make the gems be loaded first.

    Also, I think 1.2.3 or Edge Rails has a mechanism for specifying vendor/plugins load order. Make ‘gemsonrails’ first is another way to do the same without renaming.

  11. Jodi says:

    thanx for the magic Dr NIc.

    I have one reqest – can we add a sort to the gem load order?

    ala: gems.sort.each do |dir|

    otherwise it can be challenging to load dependent gems (funny – loaded alpabetically as is in osx, but on dapper no go.)


  12. Dr Nic says:

    @jodi – ok deterministic, alphabetic order it is. Nonetheless this isn’t the best approach ultimately – it should use the gems’ on dependencies to determine load order I guess, or add the /vendor/gems folder into the LOAD_PATH so they are loaded instead of the local cache’d gems. I’ll put that on the todo list.

  13. Matt Scilipoti says:

    @gemsonrails developers: This is a notice to save other developers from my mistakes. I have been tweaking gemsonrails to handle non-standard require/init conventions (patch will be shared presently). My frustration arrived when I ran ‘gem local_deploy’ and then ‘rake freeze:gem GEM=xyz’. My changes to freeze:gem were not present. Incremented Version? Check. Manual inspection of the, newly installed, gemsonrails source showed the appropriate code. I even un-installed prior gemsonrails, just in case.

    The issue? The gemsonrails gem is a fancy, shmancy code generator. I had to run ‘gemsonrails’ and actually generate the new rake tasks. Problem solved.

    In my defense, I had researched newgem and hoe, figured out how to create a local deploy, run into the sh(‘gem install…’) and the tar/zip issues on Windows AFTER I had tweaked the code in gemsonrails that generated the rake tasks. Still… you’d think it would have come to me sooner. I’m blaming 1am.

    @Dr. Nic – Thanks for this great tool – and the others too. And thank for the wonderful distraction I have had from my ‘normal project’. This has been fun! I think I even identified some of the dreaded Rake sh command issues on Windows. We’ll see.

    +1 load order by gems’ own dependencies. I’m interested in that code.

  14. [...] Гемы в качестве плагинов [...]

  15. manjax23 says:

    I am a newbie and am trying to figure out whether there any specific advantages of this plugin?
    I think We can still achieve the same functionality with gem unpack > and $LOAD_PATH.unshift >/lib in environment.rb file.

  16. Dr Nic says:

    @manjax23 [via] – currently there aren’t many more benefits than manually doing the unpack yourself + adding an init.rb. Initially it was a starting point for adding more “vendor everything” functionality. Currently, I’m leaning towards a rails patch that adds dependency support etc, written by Marcel Molina Jr. RubyGems itself is a moving target which is holding back the acceptance of the patch. Hopefully the patch is applied for Rails 2.0.

  17. manjax23 says:

    Cool, Thanks. Appreciate your plugin concept.
    I think adding/freezing gems manually would take a nerve and it would be great if your plugin could automatically identify the plugins required by the application and unpacks them along with dependency.
    Or other nicer approach would be to maintain a registry of plugins for the rails application, get the list of plugins and unpack and link (or freeze) them into the application.

  18. NAYAK says:

    I would like to know how can I load gems based on the underlying platform,
    Eg I need json gem to be freezed in my application and json gem comes in 2 version json-mswin32 and json (for linux etc). My problem is that I need to load either one of the json gem based on the underlying platform.

  19. [...] Dr Nic » RailsRally 2007 and GemsOnRails This Rails plugin allows you to freeze or link a gem into your rails source (inspired by Rick Olsen’s gems plugin) (tags: development gem gems plugin plugins rake rails rubyonrails ruby programming) [...]

  20. Adam Falcone says:

    I know this is a simple question but I’m just getting started.

    I did:
    > gem install gemsonrails

    “no problem”

    > cd rails-app-folder

    “no problem”

    > gemsonrails

    “gemsonrails command not found”

    can someone please let me know why I can’t deploy this gem to my application using the above command. Thanks.

  21. Dr Nic says:

    @Adam – if you’re using Rails 2.1 I recommend using the in-built gem support and the accompanying rake tasks.

    Regarding your problem, I just reinstalled gemsonrails and the cmd-line app appears for me. The placement of ‘gemsonrails’ application into your path is supported by RubyGems, and works in the same way that you have access to the ‘rails’ application. Not sure why it would fail.

  22. Vivs says:

    i m using magic_multi_connection gem and my site is located on VPS server which i can’t restart. But if i want my gem to work i have to write “require magic_multi_connection” of environment.rb file and to make that thing run on live server i have to restart live domain server so that environment.rb file gets executed.
    So is there any other way that i can directly upload my stuffs and make it working after freezing the gem without restarting the live server.
    If i m mistaken some where then please let me know.

  23. Tushar Gandhi says:

    Hi ,
    I am using gemsonrails for freezing the my application gems
    I have done in following order:-
    1) gem install gemsonrails
    2) cd rails_project_dir
    3) gemsonrails
    4)rake gems:freeze GEM pdf-writer
    (in /railsproject/bcms/browsercms_demo)
    DEPRECATION WARNING: Rake tasks in vendor/plugins/gemsonrails/tasks, vendor/plugins/gemsonrails/tasks, vendor/plugins/gemsonrails/tasks, and vendor/plugins/gemsonrails/tasks are deprecated. Use lib/tasks instead. (called from /Library/Ruby/Gems/1.8/gems/rails-2.3.8/lib/tasks/rails.rb:10)
    rake aborted!
    wrong number of arguments (2 for 1)

    (See full trace by running task with –trace)

    What is wrong with this. It is working on windows but not ON MAC.