Today I Learned

A Hashrocket project

5 posts by andrewvogel @calllmehvogel

Getting BetterErrors in Rails While Using Ngrok

By default, the BetterErrors gem only works for localhost. If you’re using ngrok to access your rails server and you want to have access to BetterErrors, you’ll need to whitelist the IP of the machine that ngrok is running on.

Add the following to development.rb:

# - or -
# Use an IP finding service to grab your public IP each time you start the server:
# (,, etc.)

Set the Domain or Host in Rails URL Helpers

You can explicitly set the domain with Rails URL Helpers:

=> ""

app.root_url(domain: '')
=> ""


If we include the protocol in our domain argument, this brings up an interesting gotcha. Check it out:

app.root_url(domain: '')
=> "http://www."


Thankfully, Rails gives us the host option. Host will use a Regex to remove the protocol from the argument:

app.root_url(host: '')
=> ""


Notice the output in the last example; our protocol was replaced removed and replaced with http. You can use the protocol argument to enforce your protocol on a given host:

app.root_url(host: '', protocol: 'https')
=> ""

Alias A Model Method Or Field in a GraphQL Type

If you need to override the name of a model method or field in a GraphQL type, you can use the property argument.

Let’s say we have a model called Message:

class Message < ApplicationRecord
  def bar

We can then make an alias to the bar method by specifying a property in our MessageType:

Types::MessageType = GraphQL::ObjectType.define do 
  field :foo, types.String, property: :bar