From 80eff6f897e220af5bad9c2fabcf6f6a667dc7e9 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 22 Feb 2024 22:54:40 -0600 Subject: [PATCH] Add Alter The Rails Setup Script as a Rails TIL --- README.md | 3 ++- rails/alter-the-rails-setup-script.md | 38 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 rails/alter-the-rails-setup-script.md diff --git a/README.md b/README.md index 02e5f54..64fa023 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1373 TILs and counting..._ +_1374 TILs and counting..._ --- @@ -812,6 +812,7 @@ _1373 TILs and counting..._ - [Allow List Params Anywhere With Strong Params](rails/allow-list-params-anywhere-with-strong-params.md) - [All or Nothing Database Transactions](rails/all-or-nothing-database-transactions.md) - [Alphabetize Schema Columns To Keep Them Consistent](rails/alphabetize-schema-columns-to-keep-them-consistent.md) +- [Alter The Rails Setup Script](rails/alter-the-rails-setup-script.md) - [Assert Two Arrays Have The Same Items With RSpec](rails/assert-two-arrays-have-the-same-items-with-rspec.md) - [Attach A File With Capybara](rails/attach-a-file-with-capybara.md) - [Attribute Getter without the Recursion](rails/attribute-getter-without-the-recursion.md) diff --git a/rails/alter-the-rails-setup-script.md b/rails/alter-the-rails-setup-script.md new file mode 100644 index 0000000..5aece63 --- /dev/null +++ b/rails/alter-the-rails-setup-script.md @@ -0,0 +1,38 @@ +# Alter The Rails Setup Script + +When you generate a new Rails app, a set of scripts are put in the `bin/` +folder of your new app. These _bin scripts_ are ruby scripts that you can use +to run `rails` commands, `rake` commands, as well as `setup` your rails +project. + +These scripts can be modified like you'd modify any other ruby code. + +In fact, the `setup` scripts encourages you to modify it by providing an +example of an additional setup step you can add. + +```bash +#!/usr/bin/env ruby +require "fileutils" + +# ... + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "\n== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + # ... +end +``` + +There are several steps built in, but it provides an example of how you can +copy a sample YAML file to be the actual version of that YAML file.