Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 23, 2022 04:05 am GMT

The Rails Configuration File (~/.railsrc)

Did you know that Rails has a ~/.railsrc file?

Similar to your ~/.bashrc or ~/.zshrc file, you can use this file to configure your Rails applications.

The Rails Configuration File

This is especially useful if you find yourself repeatedly typing --skip or --no-skip commands and installing specific gems every time you create a new Rails application.

Since I made a switch to Rails from .NET last year, I must have created at least 20-30 projects for either learning, experiments, or client work. I have a text file that documents all the gems I want to install for a fresh Rails app. Every time I create a new project, I go through the file to install all the gems I want for my project.

With the ~/.railsrc file, I don't need to do that. Rails will do it for me. Here's how you do this.

First, create the .railsrc file in your home directory.

touch ~/.railsrc

Add whatever options you want in this file. For example,


To see all the available options, type rails in a non-rails directory.

  rails railsUsage:  rails new APP_PATH [options]Options:      [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated engines)      [--skip-collision-check], [--no-skip-collision-check]  # Skip collision check  -r, [--ruby=PATH]                                          # Path to the Ruby binary of your choice                                                             # Default: /Users/akshay/.rbenv/versions/3.1.0/bin/ruby  -m, [--template=TEMPLATE]                                  # Path to some application template (can be a filesystem path or URL)  -d, [--database=DATABASE]                                  # Preconfigure for selected database   ...

To pre-configure the gems you'd like to install, create a template.rb file. Here's mine:

gem_group :development, :test do  gem 'dotenv-rails'  gem 'factory_bot_rails'endgem_group :development do  gem 'better_errors'  gem 'binding_of_caller'  gem 'annotate'end

Now add the path to the template at the end of your ~/.railsrc file.


That's it. The next time you run rails new app, Rails will use the configuration file along with the Gemfile template to create your application just like you want.

Pretty cool, right?

Original Link:

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To