An email newsletter, with one Ruby/Rails technique delivered with a ‘why?’ and a ‘how?’ every two weeks. It’s deliberately brief, focussed & opinionated.
From the archives…
- Express yourself clearly with positive? and negative? for numbers
- Play in a sandbox in production
- Beware of <%== in your erb files
- Really, Really, Really Don’t Interpolate Strings into Active Record Methods
- Assign a default value to an attribute in Active Record
- Consider find_each for looping through Active Record associations
- Try not to loop through associations inside jobs
- Only use locals in view partials
- Find out what callbacks are defined on an Active Record model in the console
- Safely Remove a Column from an Active Record Model
- Use zero? for comparison of numerics like Integer, Float and BigDecimal
- Time Ranges are Clearer When Querying Databases
- Time extensions are an unsung hero of Active Support
- Use before? and after? Methods When Comparing Dates and Times in Rails
- The Mrs Triggs Problem
- Know what your scopes are doing: where.first vs find_by
- Software & Infrastructure we use to Run Our SaaS
- Enqueue Jobs Quickly with Sidekiq’s Bulk Features
- Tidy Up Your Routes with Only
- Don't Use Floats and Use the Ruby Money Gem to Represent Currencies
- Use Sidekiq Directly, Not Through Active Job
- Use compact_blank to remove empty strings from Arrays and Hashes
- Compress Your HTML Responses
- Don’t call a new version of something ”new” when refactoring
- Calculate the standard deviation of a Ruby array
- Calculate the mode & median averages of a Ruby array
- Opt out of Google’s FLoC User Tracking on Netlify
- Opt out of Google’s FLoC User Tracking in Rails
- Wrap your environment variables in a settings object
- Order by created_at and updated_at with scopes and a concern
- Do not use .all without pagination or a .limit
- Be specific when defining your routes
- Turn off the bits of Rails you don't use
- Use Rails URL helpers outside views and controllers
- Use Enhanced Memoization for false/nil with defined?
- Convert a two character ISO country code to an emoji flag
- Memoize Expensive Code
- Read the .ruby-version into your Gemfile
- Alt:BrightonRuby: An Online Ruby Conference — June/July 2020
- ‘Fix’ first & last by explicitly setting implicit ordering
- All Your Mailer Views in One Place
- Calculate a mean average from a Ruby array
- Be Suspicious of Join Tables
- Use Loose Ruby Versioning in Your Gemfile
- Ensure you correctly build your caching keys
- Write One Test
- Use GitHub Actions for Rails CI with Postgres
- Use Active Support in Rails for deprecation messages
- A Active Model validator for Stripe Ids
- Use a custom validator
- Clamp for min/max values
- Consider Value Objects
- Using strftime in a Rails view is probably a mistake
- Don’t Email From Active Record Callbacks
- Watch Out For nil in Ranges
- Be Aware of nil values when using where.not()
- Prevent Links in Text Fields to Foil Spammers
- Protect your sign up form with Rack::Attack
- Clean up broken .dev domains
- Don't use instance variables in partials
- Secure Your Rails Staging Environment with HTTP Basic Authentication
- Be Careful Assigning to has_one Relations
- Replace Timecop With Rails’ Time Helpers in RSpec
- Use Multiple Migrations When Adding Database Constraints
- Always Force Booleans to be True or False
- Write long strings with wiggly HEREDOCs
- A scope should return a scope
- Don’t Loop & Do Work in Jobs
- Using pluck can save a bunch of memory
- Careful with present? when using ActiveRecord scopes
- Use the presence method
- Delegate to simplify your code
- Ignore PHP bots with Rack::Attack
- Use beginning and end of string in regular expressions
- Active Record’s first and last may not mean what you think
- A job should know whether to run itself
- Use Hash#fetch when using Rails params in controllers
- Stop robots and crawlers causing errors in your Rails application
- Check Your Database Indexes For ActiveRecord Scopes
- Only use named scopes outside models
- Avoid Writing SQL When Using ActiveRelation
- Enumerable avoids using temporary variables when looping
- Extract conditionals into well-named methods
- Be sparing when using unless
- Truthiness in Conditionals
- Set your page title in the view template using content_for
- Choose UUIDs for model IDs in Rails
- Use a pull request template
- Use simplecov in your Rails test suite
- Rescue specific errors. Avoid rescuing StandardError. Don’t rescue Exception.
- Don’t use default_scope. Ever.
- Use Rails’ naming conventions for dates & times
- Rails Naming Cringes
- AMP Project Pages on Ruby on Rails
- Simple Ruby/Rails Setup on macOS
- Benchmarking each_with_object Against inject when building Hashes from Arrays
- Serving a Jekyll Blog using Heroku
- Web Services used at ImpulseFlyer
- RedDotRubyConf 2012: Wrap up