Skip to content

Instantly share code, notes, and snippets.

@cies
Created December 18, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cies/8012974f5d762c518a7a to your computer and use it in GitHub Desktop.
Save cies/8012974f5d762c518a7a to your computer and use it in GitHub Desktop.
VM setup for Rails workshop

Rails Workshop VM

Welcome to this VM! Your username is railsws and your password (in case you need it, like when using sudo) is railsws as well.

Good luck and enjoy!

Pre-installed software (we did this for you)

Here a list of the pre-installed software on this VM.

OS:

  • Xubuntu (Ubuntu w/ XFCE desktop) 15.10
  • Updates
  • Install VirtualBox guest extensions

Shell:

  • Prezto with many modules on

Editor:

Ruby (using rbenv):

Ruby on Rails:

  • Simply by gem install rails
  • Followed by a rbenv rehash to make sure the rails command is available

Database:

  • Installed the mighty Postgres database
  • And pgAdmin
  • A database user named railsws, with password railsws, and CREATEDB permission is created

Heroku:

For you to do

For the following steps you are expected to have account for Github and Heroku. If you do not have them, please register to both services: they are totally awesome!

Setup Git:

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

Setup your keypair for SSH (your keypair is encrypted so you are asked to provide a passphrase):

ssh-keygen -t rsa -C "YOUR@EMAIL.com"

To setup Github, copy the output of this command:

cat ~/.ssh/id_rsa.pub

And paste it into the 'Add SSH key' for you find here (when logged in): https://github.com/settings/ssh

You can test it with the following command (answer yes to "Are you sure you want to connect?"):

ssh -T git@github.com

Now setup supply your Heroku account credentials to your the Heroku toolbelt:

heroku login

Basic Rails application to test all works properly

There's a very basic application in ~/Projects/testapp, merely serving as a proof that all works well. You can change to the directory with cd ~/Projects/testapp and then issue one of the following commands:

rails s                # start the development server
rails c                # open the console (CTRL-D to leave it)
rails db               # open the database prompt (CTRL-D to quit)
rails generate --help  # learn about stuff to generate
rake test              # run the test suite
rake -T                # list some common task you may run
rake routes            # list the routes<->controllers mapping

Create a new Rails app

Creating a new app called myapp is simple:

rails new myapp -d postgresql
cd myapp

Since you are logged in to the OS as a user that has also exists as a CREATEDB privileged Postgres database user, you should be able to connect to the database without specifying credentials. In case this does not work you should modify the config/database.yml file to contain the correct database user and password (in our case both are railsws).

Now create the database and start the server:

rake db:create
rails server

You can now point your browser (in this VM) to: http://localhost:3000

To create a new model --for example products-- with an accompanying views and database 'migration' run:

rails generate scaffold products name:string description:text price:float stock:integer
rake db:migrate  # create necessary table structure in the database

Using rails console (or the shortcut rails c) you can test drive your new model:

p = Product.new
p.name = "Lightsaber"
p.price = "98.85"
p.description = "You know you want it!"
p.stock = 42
p.save
Product.all

Further learning

Learn Ruby:

Learn Ruby on Rails:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment