An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
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.
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,
--database=mysql--skip-active-job--skip-spring--skip-javascript--template=~/dotfiles/rails_template.rb
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.
--template=~/software/rails/template.rb
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: https://dev.to/software_writer/the-rails-configuration-file-railsrc-4f4c
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To