1
0
mirror of https://github.com/jbranchaud/til synced 2026-03-05 07:28:46 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud
8b3ef4872c Add Apply Basic HTML Formatting To Block Of Text as a Rails TIL 2025-01-21 15:48:40 -06:00
jbranchaud
c2184a5ecf Add Hatchbox Exports Env Vars With asdf as a Devops TIL 2025-01-21 15:36:44 -06:00
3 changed files with 87 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). For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1569 TILs and counting..._ _1571 TILs and counting..._
See some of the other learning resources I work on: See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -200,6 +200,7 @@ See some of the other learning resources I work on:
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md) - [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md) - [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
- [Determine The IP Address Of A Domain](devops/determine-the-ip-address-of-a-domain.md) - [Determine The IP Address Of A Domain](devops/determine-the-ip-address-of-a-domain.md)
- [Hatchbox Exports Env Vars With asdf](devops/hatchbox-exports-env-vars-with-asdf.md)
- [Path Of The Packets](devops/path-of-the-packets.md) - [Path Of The Packets](devops/path-of-the-packets.md)
- [Push Non-master Branch To Heroku](devops/push-non-master-branch-to-heroku.md) - [Push Non-master Branch To Heroku](devops/push-non-master-branch-to-heroku.md)
- [Reload The nginx Configuration](devops/reload-the-nginx-configuration.md) - [Reload The nginx Configuration](devops/reload-the-nginx-configuration.md)
@@ -953,6 +954,7 @@ See some of the other learning resources I work on:
- [All or Nothing Database Transactions](rails/all-or-nothing-database-transactions.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) - [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) - [Alter The Rails Setup Script](rails/alter-the-rails-setup-script.md)
- [Apply Basic HTML Formatting To Block Of Text](rails/apply-basic-html-formatting-to-block-of-text.md)
- [Assert Two Arrays Have The Same Items With RSpec](rails/assert-two-arrays-have-the-same-items-with-rspec.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) - [Attach A File With Capybara](rails/attach-a-file-with-capybara.md)
- [Attribute Getter without the Recursion](rails/attribute-getter-without-the-recursion.md) - [Attribute Getter without the Recursion](rails/attribute-getter-without-the-recursion.md)

View File

@@ -0,0 +1,44 @@
# Hatchbox Exports Env Vars With asdf
When you add env vars through the [Hatchbox](https://hatchbox.io/) UI, they get
exported to the environment of the asdf-shimmed processes. This is handled by
the [`asdf-vars` plugin](https://github.com/excid3/asdf-vars). That plugin
looks for `.asdf-vars` in the current chain of directories.
I can see there are many `.asdf-vars` files:
```bash
$ find . -name ".asdf-vars" -type f
./.asdf-vars
./my-app/.asdf-vars
./my-app/releases/20250120195106/.asdf-vars
./my-app/releases/20250121041054/.asdf-vars
```
And it is the one in my app's directory that contains the env vars that I set
in the UI.
```bash
$ cat my-app/.asdf-vars
BUNDLE_WITHOUT=development:test
DATABASE_URL=postgresql://user_123:123456789012345@10.0.1.1/my_app_db
PORT=9000
RACK_ENV=production
RAILS_ENV=production
RAILS_LOG_TO_STDOUT=true
RAILS_MASTER_KEY=abc123
SECRET_KEY_BASE=abc123efg456
```
When I run a shimmed process like `ruby`, those env vars are loaded into the
process's environment.
```bash
$ cd my-app/current
$ which ruby
/home/deploy/.asdf/shims/ruby
$ ruby -e "puts ENV['DATABASE_URL']"
postgresql://user_123:123456789012345@10.0.1.1/my_app_db
```
[source](https://www.visualmode.dev/hatchbox-manages-env-vars-with-asdf)

View File

@@ -0,0 +1,40 @@
# Apply Basic HTML Formatting To Block Of Text
My Rails app has a form that allows a user to enter in free-form text. I enter
in a couple paragraphs and save the record. It is rendered on a show page with
a couple lines of ERB like so:
```ruby
<div class="max-w-3xl mx-auto">
<div class="space-y-4">
<div class="prose mt-8 text-gray-700">
<%= @record.notes %>
</div>
</div>
</div>
```
When I view the erb-displayed version of that record's text, all those
carefully spaced paragraphs are clumped together. That is because those newline
(`\n` and `\n\n`) characters while understood to be whitespace do not have
formatting implications in the browser like a combination of HTML tags and CSS
do.
I can apply some basic formatting with [the aptly named `simple_format` method
available as an `ActionView`
helper](https://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format).
```ruby
<div class="max-w-3xl mx-auto">
<div class="space-y-4">
<div class="prose mt-8 text-gray-700">
<%= simple_format(@record.notes) %>
</div>
</div>
</div>
```
This turns single `\n` characters into a `<br />` tag and double `\n\n` cause
the surrounding paragraphs to be wrapped in `<p>` tags. That simple formatting
combined with my existing TailwindCSS styles makes the formatting of my text
immediately look much better.