DEV Community

Marcio Lopes de Faria
Marcio Lopes de Faria

Posted on

Small tweaks to run a Ruby on Rails project locally

Sometimes you want just to tweak the way you run a Rails project, but without commit those changes upstream.

There are some tools that allow one to do it without much problem.

Direnv is your Ally

Dir env allows you to just ignore the rbenv .ruby-version or asdf .tool-version in a very easy way. For example if the project uses a ruby version 2.7.1 but you have installed the version 2.7.2, all you need to do is to put this on your .envrc file:

  load_prefix $HOME/.asdf/installs/ruby/2.7.2
  layout ruby
Enter fullscreen mode Exit fullscreen mode

With this, you can force the version 2.7.2 upon the Project.

Gemfile manipulation

Imagine that the Project mandates you to use Passenger, but you want to run the project locally using Puma, but without commit it to the original Gemfile. One way to do it is just to create a Gemfile.local with:

eval_gemfile "Gemfile"

gem 'passenger', require: false
gem 'puma'
Enter fullscreen mode Exit fullscreen mode

After it just, copy the original Gemfile.lock to Gemfile.local.lock and place add more one line to your .envrc file:

# what we add previously
load_prefix $HOME/.asdf/installs/ruby/2.7.2
layout ruby

# a new bundle gemfile
Enter fullscreen mode Exit fullscreen mode

With this in place, just run the commands as usual:

bundle install
bundle exec rails server puma
Enter fullscreen mode Exit fullscreen mode

Aditional notes

  1. It's important to always resync the Gemfile.local.lock when some major modification on the original Gemfile.lock happens.
  2. It's important to make sure that your .gitignore_global file will ignore properly the .envrc and Gemfile.local and Gemfile.local.lock files.

Top comments (1)

marciol profile image
Marcio Lopes de Faria

Me too. This technique is really usefull, and it's is surprising to not see more posts about it.