- rails 3.1
Specifying the correct gem dependency in your Ruby on Rails application has always been very important. Luckily, Bundler has made our lives much easier by taking care of many of the headaches for us. There have been many changes to the codebase with Rails 3.1. With Rails 3.1 on the horizon, it is increasingly important to know which versions of gems are needed for an application depending on the Rails version. Here are some things to think about when preparing for deployment.
Common Errors with Gem Versions
Below are some common errors that we have received lately on the Engine Yard AppCloud platform.
Lately, we have received an elevated amount of tickets when people try to deploy with the error:
"uninitialized constant Gem::SilentUI (NameError)". The problem is that this error does not really tell people what is wrong.
Different Bundler Versions
Most of the time, this issue can be resolved by checking the system Bundler version on your instance against the Bundler version on your development machine. If the system version is 1.0.0 or below and your machine version is 1.0.15, then the easiest thing to do is add
gem 'bundler', '1.0.15' to your Gemfile. Then just run
bundle update bundler from the command line and re-deploy your application.
no such file to load -- active_record/connection_adapters/mysql2_adapter
This is another error that does not really explain what the problem is. In Rails 3.1, the ActiveRecord MySQL2 Adapter is included by default and therefore is not provided in the mysql2 gem in versions greater than 0.3.
Rails 3.1 and Higher
For versions of Rails 3.1 and up, you just want to add
gem 'mysql2', '~> 0.3' to your Gemfile.
Below Rails 3.1
If you are using a version of Rails lower than 3.1, you need to tell bundler the version of mysql2 to use and it needs to be lower that 0.3. Adding
gem 'mysql2', '~> 0.2.7' to your Gemfile should take care of this.
What does this mean for my application?
It is increasingly important to require the correct version of your gems in your Gemfile. You should also use
bundle exec <command> from your application so you only use the gem versions specified for your environment.
A better option is to use
binstubs which are automatically installed on AppCloud instances. Just run
bin/<executable> instead of just
<executable> and your commands will be run against the application environment.