Today I Learned

hashrocket A Hashrocket project

Rails config hosts accepts regular expressions

Imagine you're running your Rails server on an ngrok instance. If you want to access your ngrok instance, you're going to need to add your specific ngrok subdomain to your config hosts.

If you ever restart your ngrok instance and get a new subdomain, you now have to change your config hosts again to match the new one.

Well, not anymore! Because now that you know you can use regular expressions, you can just do this:

Rails.application.config.hosts << /.*\.ngrok\.app/

Technically, if your use-case is just for subdomains, you can just do this:

Rails.application.config.hosts << ".ngrok.app"

But it's still nice to know you can utilize regular expressions if needed!

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.