Skip to content
Dave Strus edited this page Oct 26, 2015 · 3 revisions
$ rails new bluit -d postgresql
$ cd bluit
$ atom Gemfile

Add ruby to the Gemfile and check the Rails version.

ruby '2.2.3'
gem 'rails', '4.2.4'
$ touch .ruby-version
$ atom .ruby-version

Add version number to file

2.2.3

You need to re-navigate to the current directory in order for RVM to use the Ruby specified in .ruby-version.

$ cd .

Now we'll edit config/database.yml. Thanks to the -d postgresql switch on our rails command when initializing the project, it will be exactly as we need it already.

Once you've done that, it's time to create the database.

$ bin/rake db:create

Now we have an empty Rails app. Let's start up the server and see how it looks. Open up a new tab in Terminal and start the server.

$ bin/rails server

Now check out http://localhost:3000 in a browser, and you should see a default Rails page.

If everything looks OK, let's create a Git repo and make our first commit.

$ git init
$ git add .
$ git commit -m "Create empty Rails project."

Now that we've committed our basic, empty project, let's add a few gems that will make our lives easier.

First we'll add Bootstrap. Created by Mark Otto (@mdo) and Jacob Thornton @fat when they worked at Twitter, and now maintained independently of Twitter, Bootstrap is a front-end (HTML, CSS, JS) framework that makes it easier for developers to put together a decent, responsive UI. It makes some really common things much easier. From a certain point of view, it's a bit like scaffolding is for Rails. Serious designers typically prefer not to use it, just as serious Rails developers prefer not to use scaffolding. As this is a Rails development course, and not a web design or front-end development course, we'll use Bootstrap.

Rails 12factor makes is easier to run our app on Heroku.

pry-rails replaces the standard Rails console with Pry, an excellent alternative to the IRB shell We don't have to change the way we use the console. We just get some nice features for free, including a great mechanism for debugging.

Gemfile

gem 'bootstrap-sass'
gem 'rails_12factor', group: :production
gem 'pry-rails', group: [:development, :test]

Let's run Bundler to get these gems installed.

$ bundle

In order to actually use Bootstrap's styles, we'll need to include its stylesheets in app/assets/stylesheets/application.css.

app/assets/stylesheets/application.css

@import "bootstrap-sprockets";
@import "bootstrap";

And since we're using the SASS version of Bootstrap, we actually need to change the file extension of application.css from .css to .scss. We'll talk more about SASS and SCSS later. You can rename it in Terminal, or graphically within Atom.

$ git mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss

Since we re-ran Bundler, restart your server and refresh the app in your web browser. If nothing appears to have broken, let's review our changes and make another commit.

$ git status
$ git diff
$ git add .
$ git commit -m "Add Bootstrap, Rails 12factor, and Pry."