Rails development headaches on Windows
I have lost a couple of hours setting up RubyMine for Rails development on Windows today so I am going to capture the details in a blog post so it might help others. First I have to admin I have kind of a peculiar setup. I am working on some Ruby on Rails side projects but my main machine is a windows 10 which is not recommended for Rails development since many of the dev tools are not fully tested/supported on windows.
The main idea here is to create a Linux VM to act as our rails server and use RubyMine on our windows machine to do the actual dev. Vagrant ensures that files are synchronized between host and gust OSs so as soon as you save your changes the server has the same version of the files. When needed we can debug the server using RubyMine’s remote debug or Rails console.
Part I - Setting Up vagrant
I use Vagrant to setup a virtual machine and found a couple of existing boxes with rails 5 already installed in the repository. In order to use vagrant to manage your dev VMs you have to install it and define the box you want to use. all you have to do is to run
vagrant init in an empty folder and update the
config.vm.box variable inside
VagrantFile that is generated to the name of the box you want to clone. This is how my
VagrantFile looks like.
Vagrant.configure("2") do |config| config.vm.box = "jadesystems/rails5" end
Then all you have to do is to start the VM using
vagrant up. Wait about a minute and your VM will be up and running with everything you need to start coding. Now the VM is headless which is to say you don’t get a nice GUI and you have to use ssh to run console commands on you dev machine but that’s not an issue since we are going to configure RubyMine on our windows machine and use the VM only to run the code.
In order to run any code on the new VM you have to connect to the machine via SSH. to do that run
vagrant ssh inside the folder that contains the
VagrantFile. If you get an error there is a good chance you don’t have ssh.exe in your path and you have to install it. There is a SSH client inside git so search your git installation path for the file and add it to windows Path.
when you connect to the ssh you will get a prompt. run
cd /vagrant and you shall find yourself inside an special folder. if your run
ls you see that currently you only have a VagrantFile in that folder but this is the same folder that exists in your host OS. all you have to do is to copy your rails app to the same folder you have your VagrantFile (on Windows) and they appear on the servers
Now you can run your Rails application on the server using
rails server -b 0.0.0.0 -p 3000
The reason we have to specify binding port is to make sure the server is available from other machines (in this case the host operating system). The port should be forwarded to the host operating system (the 3000 is by default). Now the server should be available on the host operating system at http://localhost:3000
# Part II RubyMine remote SDK setup
In order to be able to debug and run tests on the remote dev server we just created we need to configure RubyMine.
Go to File > Settings > Language and Frameworks > Ruby SDK and Gems and click on the add new SDK button and choose New Remote…