Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Setting Up Rails and Reservations for Development

Sydney Young edited this page Oct 9, 2016 · 7 revisions

Notes on this guide

  • You should be running some sort of UNIX operating system, preferably NOT in a virtual machine.
  • For brevity, this guide only includes specific instructions for OSX and Ubuntu, but the Ubuntu instructions should work for most flavors of linux. (It may also include Arch Linux at a later date, because the installation process is slightly more involved than Ubuntu and will provide more assistance for people that don't use Ubuntu)
  • This guide also assumes you're using bash. If you don't know what that means, but you're running OSX or Linux, you're probably running bash; proceed.
  • If you're running OSX, first install xcode and then homebrew.
  • If you run into any issues during the setup process, please let me know so that I can update this guide!

A Text Editor

This can be a controversial subject, but if you don't already have a favorite text editor, we recommend installing Sublime, or, if you're feeling up to a challenge (and because the author of this guide is biased), learn to use vim.

MySQL

OSX

In a terminal, run

brew install mysql

When homebrew finishing installing, you'll set up MySQL to run at login:

ln -sfv /usr/local/opt/mysql/*plist ~/Library/LaunchAgents

...and then run it now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Note that, by default, the root MySQL user has no password (this will be important later when you're configuring Reservations).

Ubuntu

Install MySQL:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Make a note of the root password that you enter during the install process, as this will be important later when you're configuring Reservations.

rbenv

OSX

Use homebrew to install rbenv, a ruby version manager:

brew install rbenv ruby-build

Setup rbenv to load every time you open a terminal:

echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

Install a ruby version:

rbenv install 2.3.1

Set the default version to 2.3.1:

rbenv global 2.3.1

To make sure that rbenv is working, run which ruby The result should include .rbenv/shims/ruby

Ubuntu

Install some dependencies:

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Install rbenv:

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Note that if you're not running Ubuntu, you should use bash_profile instead of bashrc.

Next, restart your terminal and run:

type rbenv

If it outputs rbenv is a function, you're all set.

Install ruby-build:

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Install a ruby version:

rbenv install 2.3.1

Set the default version to 2.3.1:

rbenv global 2.3.1

To make sure that rbenv is working, run which ruby The result should include .rbenv/shims/ruby

Configuring Git

Run the following commands, replacing the placeholders with the information you use with github:

git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR@EMAIL.com"

Next, set up an SSH key

Reservations

Finally, setting up the app itself! First, clone the repository:

git clone https://github.com/YaleSTC/reservations.git

Then copy some example config files:

cp config/database.yml.example.YOUR_OS config/database.yml
cp config/secrets.yml.example config/secrets.yml

Setup the database: edit the config/database.yml file to include your MySQL root password for all environments:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: reservations_development
  pool: 5
  username: root
  password: YOUR_MYSQL_PASSWORD
  socket: /var/run/mysqld/mysqld.sock
  host: localhost

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: reservations_test
  pool: 5
  username: root
  password: YOUR_MYSQL_PASSWORD
  socket: /var/run/mysqld/mysqld.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: reservations_production
  pool: 5
  username: root
  password: YOUR_MYSQL_PASSWORD
  socket: /var/run/mysqld/mysqld.sock

(Note that using the root user isn't the best practice, but this is a guide designed for beginners and using the root user is much simpler.)

Install ruby 2.3.1:

rbenv install 2.3.1

Install bundler:

gem install bundler

Install required gems:

bundle install

Use rake to build the database:

rake db:create
rake db:migrate
rake db:reset

(Note that the last command populates the database through our seed script.)

Run Reservations:

rails s

Optional Plugins

rbenv-binstubs

Never type bundle exec again!

mkdir -p ~/.rbenv/plugins
cd ~/.rbenv/plugins
git clone https://github.com/ianheggie/rbenv-binstubs.git 

Then, in your reservations directory:

bundle install --binstubs .bundle/bin rbenv rehash

rbenv-gem-rehash

Never run rbenv rehash again!

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

Thank you to this OSX rails install guide, and this Ubuntu rails install guide; most of the content of this article is pieced together from them.