Stop Turbolinks from adding multiple script tags with nonce

If you’re using a Content Security Policy (CSP) in your Rails app you probably already know how finicky things can get. One common annoyance you may run into is an issue where a script tag is added to the <head> over and over again with each page request. It’s no bueno, but there’s a way around it.

Let’s assume the fo...

Using private NPM packages with Rails, Heroku and Github

There are numerous reasons why you’d want to leverage the following setup. However, I’m going to be using a trivial example of sharing some CSS styles across different Rails apps via an npm package. That npm package will be private and hosted on GitHub. After we install the package into our Rails project via Yarn, we’l...

How to handle time in Rails

Handling time is a doozy. It’s not necessarily a problem that is specific to Rails either. It’s just hard. There are a thousand things to consider. I want to help you get an idea of what a reasonable setup might look like and let you go from there. The following steps are meant to be more conceptual than a line-by-line...

Cleaning up figures in Action Text

Action Text and Trix are great and give you an immense amount of power right out of the box. That being said, I didn’t like a bit of the styling for both the presentation of the figure to the user and in the editor. So let’s fix it!

  • You’re using Bootstrap 4
  • You’re starting from a fresh install of Action Text

If you...

Customizing the Trix toolbar

I recently added the Trix Editor to a Rails app I was working on and quickly found that I was going to need to do some modifications to the toolbar buttons. Out of the box, Trix only gives you an h1 button for creating headers and the site I was building was already populating an h1 tag via a separate field. Therefore,...

Categories in a Rails App

Categorizing things in a Rails app is a common need, but it’s a non-trivial lift to get it all implemented. Database relationships need to be right. How in the world should you set up your forms? What’s going on in my controllers? I’m going to do my best to show you how I implement categories.

Here’s our little todo l...

A gotcha with Active Storage and Cloudflare

Rails 5.2 introduced Active Storage and it’s pretty awesome. I’d used paperclip from the @thoughtbot folks for a long time, but file uploading is a requirement for just about any site these days so it might as well be part of the core. Now it is.

Well, if you happened to implement Active Storage into your Rails app an...

Debugging in RubyMine with Rails 5.2

If you’ve upgraded to Rails 5.2 and are using RubyMine’s debugger you might notice that breakpoints aren’t working as they should. For me, they would only work in views, but controllers and models wouldn’t stop anything.

Turns out the problem is the inclusion of the Bootsnap gem in Rails 5.2. Bootsnap is awesome so yo...

Custom validation in Rails

Here’s a little trick I like to do when I’m addressing validations in my models. Let’s say you have a standard Post model. It might look something like the following.

If you’re like me and prone to ideas popping into your head at inopportune times then you probably only have a few seconds to jot down an idea before yo...

System Tests with RSpec, Rails, Capybara, and Devise

Since the release of RSpec 3.7 we’ve been able to take advantage of system tests which are new as of Rails 5.1. If you’ve been using RSpec for a while you’re already likely familiar with feature tests using Capybara. For those new to these types of tests: they allow us to test the actual actions of a user. Clicking, fi...

About These Posts

Matt Haliski's mug

My blog primarily contains writings about my work on computers, but I occasionally mix in fun life stuff. I am, at best, a mediocre writer, but I like doing my part to give back to the community. Feel free to contact me if you have specific something to chat about. See you around!