1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Alter The Rails Setup Script as a Rails TIL

This commit is contained in:
jbranchaud
2024-02-22 22:54:40 -06:00
parent d5470db75b
commit 80eff6f897
2 changed files with 40 additions and 1 deletions

View File

@@ -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)

View File

@@ -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.