[Quicky] Self contained Rails script
![[Quicky] Self contained Rails script](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1710318775142%2Fe0d2022e-d354-4a20-beaa-be398dda5cc6.png&w=3840&q=75)
10+ years most with Ruby on Rails and JavaScript frontend and some Go. My first language is C for 3 years in university.
Search for a command to run...
![[Quicky] Self contained Rails script](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1710318775142%2Fe0d2022e-d354-4a20-beaa-be398dda5cc6.png&w=3840&q=75)
10+ years most with Ruby on Rails and JavaScript frontend and some Go. My first language is C for 3 years in university.
No comments yet. Be the first to comment.
I recently updated from Slim template to ERB to use Herb (Thanks Marco). I had to update a test that was very strict on the format. I realized that Capybara::Node::Simple doesn’t provide a selector for regex. The page object doesn’t have a match? met...

It is as simple as: rustup completions zsh > ~/.zfunc/_rustup rustup completions zsh cargo > ~/.zfunc/_cargo With a TAB you get the auto-complete or the options available: ❯ cargo b b -- alias: build bench -- Execute all benchmarks of a local ...
Let’s not re-write a good article, go to: https://joyofrails.com/articles/mastering-custom-configuration-in-rails I mostly used config.x configuration that loads a yaml file with config_for that do the multi-environment by default: module YourApp c...
No need to re-write the wheel, let me redirect to this great article from Lily Reile. Obviously still up-to-date and really useful as the official Rails doc is mostly showing the value before and after. https://lilyreile.medium.com/rails-6-1-new-fram...
I came around to update Appsignal gem to the new major version of Appsignal released at the end of August 2024: https://rubygems.org/gems/appsignal/versions/4.0.0 The upgrade was smooth. The real change for my application was to remove the parameter ...
To run a script with your Rails application setup use rails runner https://guides.rubyonrails.org/command_line.html#bin-rails-runner
# inline script
./bin/rails runner "puts Rails.env"
# file
./bin/rails runner path/to/file.rb
If you want to have a self container, here's what you need (eg: filename bin/puts_env):
#!/usr/bin/env ruby
APP_PATH = File.expand_path("../../config/application", __FILE__)
require File.expand_path("../../config/boot", __FILE__)
require APP_PATH
Rails.application.require_environment!
###### Your script below
puts Rails.env
Don't forget to make the file executable:
chmod +x bin/puts_env
Now you can run the script, no more need to remember how to run it, just do:
./bin/puts_env