The Captain's Log

Tales of achievement, bewilderment, and a surly relationship with a computer.
Tagged with: rails
A gotcha with Active Storage and Cloudflare
April 24, 2018
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...
Categories in a Rails App
April 21, 2018
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...
Debugging in RubyMine with Rails 5.2
April 04, 2018
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....
Custom validation in Rails
February 15, 2018
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. create_table "posts", force: :cascade do |t| t.string "title" t.text "body" t.integer "status" t.datetime "published_at" t.datetime "created_at", null: false t.datetime "updated_at",...
System Tests with RSpec, Rails, Capybara, and Devise
February 14, 2018
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...
ActionMailer SMTP settings for SendGrid (Rails)
March 30, 2017
Okay, I got no Google hits for this. Here’s a tip if you’re using SendGrid in a Rails app for your transactional emails. A while back you needed to provide your SendGrid username and password (hopefully via environment variables), but now you can use an app-specific api key. Here’s some...
Heroku defaults to Puma for Rails 5
May 02, 2016
It’s now going to be easier than ever to kick off a new Rails project and deploy to Heroku. WEBrick is no longer the default server with Rails 5. If you don’t provide a Procfile Heroku is going to help you out and set you up with Puma. Production ready...
How to Create a Contact Form Using Rails and Mandrill
February 08, 2016
Let’s build a simple contact form for your Rails driven website that uses Mandrill as the desired email server. Mandrill lets us offload the management of setting up and running an email server ourselves and, therefore, relieving ourselves of a massive headache. Mandrill starts you with 2,000 free trial sends...
Syntax Highlighting in Rails
February 01, 2016
Your Rails driven website has the need to display some code. It’s not good enough to just get proper indentation, you’d like to have some decent syntax highlighting. Maybe something like following.
Editing a form using fields_for in Rails
January 18, 2016
Let’s say you’d like to successfully create or update a nested form using fields_for. Our ‘parent’ will be a Post model and our ‘child’ will be a Tag model. It’s not hard, but there’s a bit of a gotcha that I found most other resources out there were leaving out....