1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-05 16:18:01 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud
89a645a42a Add Make An Executable Ruby Script as a Ruby TIL 2022-06-10 15:10:49 -05:00
jbranchaud
00232403f7 Add Get Help With A Rails App Update as a Rails TIL 2022-06-10 14:26:00 -05:00
3 changed files with 70 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).
_1223 TILs and counting..._
_1225 TILs and counting..._
---
@@ -749,6 +749,7 @@ _1223 TILs and counting..._
- [Get ActiveRecord Attribute Directly From Database](rails/get-active-record-attribute-directly-from-database.md)
- [Get An Array Of Values From The Database](rails/get-an-array-of-values-from-the-database.md)
- [Get An Empty ActiveRecord Relation](rails/get-an-empty-activerecord-relation.md)
- [Get Help With A Rails App Update](rails/get-help-with-a-rails-app-update.md)
- [Get The Column Names For A Model](rails/get-the-column-names-for-a-model.md)
- [Get The Current Time](rails/get-the-current-time.md)
- [Grab A Random Record From The Database](rails/grab-a-random-record-from-the-database.md)
@@ -1000,6 +1001,7 @@ _1223 TILs and counting..._
- [Limit Split](ruby/limit-split.md)
- [List The Running Ruby Version](ruby/list-the-running-ruby-version.md)
- [Listing Local Variables](ruby/listing-local-variables.md)
- [Make An Executable Ruby Script](ruby/make-an-executable-ruby-script.md)
- [Map With Index Over An Array](ruby/map-with-index-over-an-array.md)
- [Mock Method Chain Calls With RSpec](ruby/mock-method-chain-calls-with-rspec.md)
- [Mocking Requests With Partial URIs Using Regex](ruby/mocking-requests-with-partial-uris-using-regex.md)

View File

@@ -0,0 +1,29 @@
# Get Help With A Rails App Update
Rails version upgrades can be pretty involved. The ecosystem and the framework
are under constant evolution. While each patch version will stay reliably
stable, as soon as you go to do a minor or major upgrade (which you should stay
on top of), you'll have lots to consider.
Rails helps with this via the `app:update` rake task.
When run, it will prompt you with a series of files that it wants to change.
For each one you'll have some options.
```bash
$ rails app:update
Overwrite my-app/config/boot.rb? (enter "h" for help) [Ynaqdhm] h
Y - yes, overwrite
n - no, do not overwrite
a - all, overwrite this and all others
q - quit, abort
d - diff, show the differences between the old and the new
h - help, show this help
m - merge, run merge tool
```
Start by using `d` to see a diff of the changes. If it's small and doesn't
overwrite important, existing settings, then you can use `y` to accept them.
For a lot of these files the changes will be too aggressive. So side-by-side
with the diff, update the file manually. Then use `n` to go to the next update.

View File

@@ -0,0 +1,38 @@
# Make An Executable Ruby Script
In a unix environment with Ruby available, I can make a Ruby script. To do this
I stick some code in a Ruby file, like `database_url.rb`.
```ruby
result = `heroku pg:credentials:url DATABASE_URL --app my-app`
puts result.split("\n")[2].strip
```
And then execute that file with `ruby`:
```bash
$ ruby database_url.rb
```
I can instead make an executable file that doesn't need to be explicitly
invoked with the `ruby` command. To do this, I need to prefix my file with a
[shebang](https://unix.stackexchange.com/a/87600/5916) for
[`ruby`](https://devcenter.heroku.com/articles/ruby-binstub-shebang).
And I'll even just call the file `database_url` now, no file suffix.
```ruby
#!/usr/bin/env ruby
result = `heroku pg:credentials:url DATABASE_URL --app my-app`
puts result.split("\n")[2].strip
```
When executed, this script will see the first line and understand that it needs
to execute the rest of the script using `ruby` as the interpreter.
Like any other executable, you can call it as is, like so:
```ruby
$ database_url
```