JAN 18 January 18, 2024

Developing with Browser Guards in Rails 8 - As part of the Rails 8 milestones, DHH added a browser guard which he explains thus:

To take full advantage of our #nobuild defaults, we need to ensure that developers have easy control over which versions of the major evergreen browsers they intend to support, and guard their application from being accessed by unsupported versions.

In the pull request that followed we can see that by default, the browser minimums have been set to:

  • Safari 17.2
  • Chrome 119
  • Firefox 121
  • Opera 104
  • and well, no IE at all.

What this means in practice is that if you visit a newly generated Rails site with a browser below these versions, you will get this 426 error page:

Image

[read more...]


JAN 5 January 5, 2024



NOV 4 November 4, 2022

Prefer Writing - At the end of last year, I recorded 3 screencasts that I felt would be interesting to the Ruby on Rails community. I put them out into the world and the response was largely positive. But to me, it didn’t feel right. Recording a video to explain things does not come naturally to me. I prefer to write.

Whilst I don’t mind consuming screencasts, and I’ve learned a lot of Ruby on Rails techniques from fabulous screencasts like Railscasts, Destroy All Software, Go Rails and Drifting Ruby, and countless YouTubers, my preference is reading a long-form blog post or book.

[read more...]


JAN 14 January 14, 2022

Intro to Raycast For Developers - Quick demo of setting up Raycast to search the Tailwind and Devdocs documentation.


DEC 28 December 28, 2021


DEC 12 December 12, 2021


OCT 12 October 12, 2021

Rails 7: Fix yarn missing on Heroku - When deploying Rails 6 sites to Heroku, the Ruby buildpack would detect if the webpacker gem was installed and install yarn for you automatically. With Rails 7, webpacker is no longer installed by default, so using jsbundling-rails and extras that require yarn to be installed will cause deployment errors on Heroku.

The fix is to install the nodejs buildpack. This needs to be done before the ruby buildpack. As follows:

heroku buildpacks:clear
heroku buildpacks:set heroku/nodejs
heroku buildpacks:add heroku/ruby

After running these commands your deployment to Heroku will work great.


OCT 11 October 11, 2021

Rails 'new' customizations for Rails 7 - With Rails 7 and its plethora of new javascript and css configuration options and flags, it can be quite challenging to remember just what these options are when creating a new app.

For quite some time Rails has had the ability to read in a config file you have in your home folder named .railsrc This file contains the various flags you would otherwise pass into ‘rails new’ manually. By putting your preferred options/flags into this file, every Rails app you create will be created consistently and just the way you like it.

I prefer postgres as my database and esbuild for my javascript processing and tailwind as my css framework. So my .railsrc file looks like this

--database=postgresql
--javascript esbuild
--css tailwind

Now I just start a new Rails app with

rails new brilliant_app_idea

And my new app is ready to rock configured just the way I prefer.


APR 9 April 9, 2021


Using specific Node JS versions in Github Actions - Sometimes you may want to run your Github Actions using a specific version of NodeJS (eg version 8). This can come in handy if you are dealing with a legacy application and needing to compile a specific version of node-sass for example.

The way to do it is to add the following lines into your workflow file.

- uses: actions/setup-node@v2
  with:
    node-version: "8"


See what javascript caused an attribute to change - I was working on some front-end code today - and when I clicked on a checkbox it mysteriously shrunk. I mean its height was set to 0px when I clicked on it. It was so strange. Some code somewhere was adding a style attribute with height: 0px. Searching my codebase I couldn’t find anywhere where this was happening.

To solve these sorts of issues, Chrome (and I’m sure other browsers) have a feature in the dev-tools where you can stop execution and see what is happening under the hood so to speak - in other words see what javascript is running at exactly the moment a particular event happens on the DOM.

To access this feature - open up dev tools - and select the element you want to watch change. Right-click the element and in the Break on fly out menu select attribute modifications.

Attribute Modifications

Now you will need to trigger the event. In my case, I clicked on the checkbox. Execution stopped and the browser popped up the exact code that was causing the checkbox to have a style attribute added.

A very handy feature.


FEB 10 February 10, 2020

Execution order of after_commit and after_rollback ActiveRecord callback - Rails allows the adding of various callbacks that trigger during the lifecycle of an ActiveRecord operation. The standard callbacks are before_validation, after_validation, before_save, before_create, after_create, after_save, after_commit, and after_rollback.

These are documented quite extensively in the Rails Guides and the Rails API documentation.

The documentation is quite good at showing you the order the callbacks are executed - eg before_validation fires before validate which fires before before_save etc. Most of these validations execute in the order they are defined. For example, if you have two before_save callbacks defined, then they will execute one after the other.

[read more...]