Rails: Different flavors of concatting HTML safe strings in helpers
This card describes different flavors for concatting HTML safe strings in a helper method in Rails. You might want to...
Using rack-mini-profiler (with Unpoly)
Debugging performance issues in your Rails app can be a tough challenge. To get more detailed insights consider using the...
Rails 7.1: Take care of the new production log default to standard out
Starting with Rails 7.1 the production logger is set to standard out. For applications running with opscomplete ensure to keep...
Rails: Testing file downloads with request specs
tl;dr Prefer request specs over end-to-end tests (Capybara) to joyfully test file downloads! Why? Testing file downloads
Chaining Capybara matchers in RSpec
You can chain multiple Capybara matchers on the page or any element: expect(page) .to have_content('Example Course')
Be careful when checking scopes for blankness
Today I stumbled across a pretty harmless-looking query in our application which turned out to be pretty harmful and...
Use <input type="number"> for numeric form fields
Any form fields where users enter numbers should be an . Numeric inputs have several benefits over : On mobile or tablet...
How to configure Selenium WebDriver to not automatically close alerts or other browser dialogs
tl;dr We recommend configuring Selenium's unhandled prompt behavior to "ignore". When running tests in a real browser, we...
Best practices: Writing a Rails script (and how to test it)
A Rails script lives in lib/scripts and is run with bin/rails runner lib/scripts/.... They are a simple tool to perform...
Ignore commits when git blaming
You can ignore certain commits when using git blame with the --ignore-revs-file option. This is handy to ignore...
open-next-failure: An alias to speed up test debugging
Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is...
Gitlab: How to cancel redundant pipelines
In the Gitlab settings the flag Auto-cancel redundant pipelines is enabled by default. This auto-cancels jobs that have...
Rails: Pluck across associated tables
#pluck is commonly used as a performant way to retain single database values from an ActiveRecord::Relation Book.pluck(:title, :price...
A reasonable default CSP for Rails projects
Every modern Rails app should have a Content Security Policy enabled. Very compatible default The following "default" is a minimal...
Zeitwerk: How to collapse folders in Rails
All direct child directories of app are automatically added to the eager- and autoload paths. They do NOT create a...
PSA: Be super careful with complex `eager_load` or `includes` queries
TLDR Using .includes or .eager_load with 1-n associations is dangerous. Always use .preload instead. Consider the following ActiveRecord...
Heads up: Quering array columns only matches equally sorted arrays
Given you have an array column like this: create_table "users", force: :cascade do |t| t.integer "movie_ids", default: [], array...
How to make sure that manual deploy tasks (scheduled in Pivotal Tracker) are executed on deploy (with Capistrano)
We regularly have tasks that need to be performed around a deploy. Be it to notify operations about changed application...
Split your parallel tests by execution time and keep execution logs up to date
Both knapsack and parallel_tests have the option to split groups by historic execution time. The required logs for this...
redirect_to and redirect
There are multiple ways to redirect URLs to a different URL in Rails, and they differ in small but important...
Do not pass params directly into url_for or URL helpers
Rails' url_for is useful for generating routes from a Hash, but can lead to an open redirect vulnerability.
Do not use "permit!" for params
Rails' Strong Parameters enable you to allow only specific values from request params to e.g. avoid mass assignment.
Minifying object properties in JavaScript files
An introduction to mangling When you minify ("compress", "optimize") your JavaScript for production, the names of your functions and variables...
CarrierWave: Processing images with libvips
When you write your next CarrierWave uploader, consider processing your images with libvips instead of ImageMagick. Reasons for libvips