Local with local Rails app

Hey guys,
I’m a Rails developer (guy behind the back-end side of Cart66) and I was wondering if anyone knew of a quick way to get a site in Local talking to a local Rails app running in macOS. I know Local uses VirtualBox and Docker behind the scenes, so I’m thinking it might just be some tweaks to the network settings somewhere in there.

Here is the scenario, we have a WordPress plugin that connects to our Rails app and I’d like to be able to use Local to do my local testing of all of this (instead of MAMP, which I’ve used up until now). So if I have a site in Local with a URL of http://cart66-site.local, it’d be cool if I could have it communicate with my local Rails app running at http://api.cart66.test. I haven’t dipped my toe too far into the Docker pool yet, so I’m not entirely sure if some network settings can be changed in there and/or VirtualBox to make this happen. If so, that would be cool.

Any of you guys tried doing something like this?

Joey Beninghove
CTO, Cart66

Hey Joey,

I’ve been looking into this a while and I’ve run into some blockers so it’s only half of a solution for now.

Here’s what you can do:

  1. You need the IP that every container will see your computer as (what’s traditional See IP of HOST available within site container? for instructions on how to get that. It’s as simple as running one command in Terminal.
  2. Open Local and right-click on the site you want to connect to your Rails app
  3. Click “Open Site SSH”
  4. Enter nano /etc/hosts
  5. Add a new hosts entry for the Rails app. It should look something like: my-local-rails-app.localhost

Once you do that, you should be good.

The one major caveat is the fact that this will not persist the next time the site is restarted in Local. We’d like to add the ability to run scripts on certain site events like stop, start, restart, etc.

1 Like

This worked great, thanks so much Clay!

1 Like

Dude! That totally worked! Thanks man, this is great! I keep Local running pretty much all the time, so yeah, I’ll just have to keep in mind that I’ll need to do this whenever I do end up restarting or creating a new site. As you said, it’d be great to run scripts whenever a new container is spun up to make this even easier in the future.

Thanks again for the help!

Rock on, glad to hear!