Skip to content

Commit 80eff6f

Browse files
committed
Add Alter The Rails Setup Script as a Rails TIL
1 parent d5470db commit 80eff6f

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1373 TILs and counting..._
13+
_1374 TILs and counting..._
1414

1515
---
1616

@@ -812,6 +812,7 @@ _1373 TILs and counting..._
812812
- [Allow List Params Anywhere With Strong Params](rails/allow-list-params-anywhere-with-strong-params.md)
813813
- [All or Nothing Database Transactions](rails/all-or-nothing-database-transactions.md)
814814
- [Alphabetize Schema Columns To Keep Them Consistent](rails/alphabetize-schema-columns-to-keep-them-consistent.md)
815+
- [Alter The Rails Setup Script](rails/alter-the-rails-setup-script.md)
815816
- [Assert Two Arrays Have The Same Items With RSpec](rails/assert-two-arrays-have-the-same-items-with-rspec.md)
816817
- [Attach A File With Capybara](rails/attach-a-file-with-capybara.md)
817818
- [Attribute Getter without the Recursion](rails/attribute-getter-without-the-recursion.md)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Alter The Rails Setup Script
2+
3+
When you generate a new Rails app, a set of scripts are put in the `bin/`
4+
folder of your new app. These _bin scripts_ are ruby scripts that you can use
5+
to run `rails` commands, `rake` commands, as well as `setup` your rails
6+
project.
7+
8+
These scripts can be modified like you'd modify any other ruby code.
9+
10+
In fact, the `setup` scripts encourages you to modify it by providing an
11+
example of an additional setup step you can add.
12+
13+
```bash
14+
#!/usr/bin/env ruby
15+
require "fileutils"
16+
17+
# ...
18+
19+
FileUtils.chdir APP_ROOT do
20+
# This script is a way to set up or update your development environment automatically.
21+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
22+
# Add necessary setup steps to this file.
23+
24+
puts "\n== Installing dependencies =="
25+
system! "gem install bundler --conservative"
26+
system("bundle check") || system!("bundle install")
27+
28+
# puts "\n== Copying sample files =="
29+
# unless File.exist?("config/database.yml")
30+
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
31+
# end
32+
33+
# ...
34+
end
35+
```
36+
37+
There are several steps built in, but it provides an example of how you can
38+
copy a sample YAML file to be the actual version of that YAML file.

0 commit comments

Comments
 (0)