The first gathering of the #CodeQuarters hangout was really a review on my previous posts about setting up a development environment. In my previous post, I started out with creating the environment for Python and get a quick Django app up and running. This time, I'll be setting up the Ruby environment and getting MongoDB up and running. There will be plenty of overlap, but here goes:
Vagrantfile:
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 3000, host: 3000 config.vm.provider "virtualbox" do |vb| vb.memory = "1024" vb.name = "Ruby" end end
Mongo should be started, but check if it is running correctly by seeing if /var/log/mongodb/mongod.log has the following on the last few lines:
[initandlisten] waiting for connections on port
For those with small hard drive space, it would be great to lower the journaling amount that MongoDB takes up. Do this by editing /etc/mongod.conf to have mmapv1 set like the below to the storage section:
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true mmapv1: smallFiles: true # other configs: # ...
Have Mongo load the new configuration and restart it:
mongod -f /etc/mongod.conf sudo service mongod restart
OK. Let's get Rails started! Note: my personal preference is to have all my dependencies attached to my project/app directory. I know bundle handles it all, but I like to have everything encapsulated. This is why I run the --path flag and specify the local directory for my gems.
NOTE: On Windows machines, the local path will fail to build properly as Windows does something funky with the shared drive on VirtualBox. Therefore, you'll have to specify a different location for the gemsets for the project (i.e. ~/gemsets/{PROJECT_NAME} or something)
We run --skip-bundle and --skip-active-record because we want to use the same gemset directory for our Rails app and since we're using Mongo, we're not going to install active record. This is based off of this guide on the office MongoDB pages.
bundle install --path ./gemset bundle exec rails new {APP_NAME} --skip-bundle --skip-active-record cd {APP_NAME}
Add mongoid to the Gemfile that Rails created (vim Gemfile or use a text editor on the host machine) and run bundle install to the gemset directory:
vim Gemfile ... (see below) bundle install --path ../gemset gem 'mongoid', '~> 5.0.0'
Generate the Mongoid config file and begin (referencing this guide)
bundle exec rails g mongoid:config # example use of scaffold: bundle exec rails g scaffold person name street city state