Skip to content

Running on virtual machines

Mike Glenn edited this page Aug 24, 2018 · 8 revisions

Editor links

If your Rails app is running from a shared folder in a virtual machine (Vagrant or Docker for example), the path to your source files from Rails' perspective will be different to the path seen by your editor.

You can adjust the path used to generate open-in-editor links using the vagrant-host-path gem.

You then add the following to your project's config/environments/development.rb:

if defined?(BetterErrors)
  BetterErrors.editor = proc { |full_path, line|
    full_path = full_path.sub(Rails.root.to_s, ENV["VAGRANT_HOST_PATH"])
    "subl://open?url=file://#{full_path}&line=#{line}"
  }
end

For VS Code:

if defined?(BetterErrors)
  BetterErrors.editor = proc { |full_path, line|
    full_path = full_path.sub(Rails.root.to_s, ENV["VAGRANT_HOST_PATH"])
    "vscode://file#{full_path}:#{line}"
  }
end

Allowing access to your IP address

The following can be added to your config/environments/development.rb. When you connect to the virtual machine to run your project, it will allow the IP address that you are connecting from.

if defined?(BetterErrors) && ENV["SSH_CLIENT"]
  host = ENV["SSH_CLIENT"].match(/\A([^\s]*)/)[1]
  BetterErrors::Middleware.allow_ip! host if host
end
Clone this wiki locally