Intro to Rails



Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.

Some "rules"

  • We are here for you!
  • Every question is important
  • Help each other
  • Have fun

What we will cover today

  • User Authentication with Devise Gem
  • Deploying to Heroku
  • Seed Data (time permitting)


Gems are ruby libraries or programs. They're simultaneously the best and worst thing about Rails.

You can add all sorts of amazing functionality to your app with very little effort via a gem, but then you have to deal with versioning and conflicts between gems.

Gems are specified in your app's Gemfile. Running 'bundle install' ensures you have all gems available locally, and updates your Gemfile.lock file.

It is very common to break up your Gemfile into groups that correspond to Rails environments: test, development, production.


Devise documentation

We are going to follow the documentation's instructions, as it is well maintained and accurate.


As of this writing, steps for Devise setup are:

  1. Add Devise to Gemfile
  2. Bundle Install
  3. Run Devise generator
  4. Do the things suggested in setup message
  5. Generate devise User model
  6. Run 'rake db:migrate'
  7. Create sign up/in/out links in application.html.erb
  8. Add before filter for protected actions in a controller


Tool check!

$ heroku --help
$ git --help             

If you don't get help menus back, get a TA to help you install Heroku and Git correctly.


Let's follow Railsbridge's instructions.

There is one correction- step 4 on the next slide.


As of this writing, steps to deploy to Heroku are:

  1. Create Heroku app in command line
  2. Edit the Gemfile to add Postgres to appropriate groups
  3. Apply the Gemfile changes
  4. Change the production group in config/database.yml to:
      adapter: postgresql
      database: db/production            
  5. Add and commit changes with Git
  6. Push to heroku
  7. Run database migrations and seed data in terminal
  8. Visit application, be super proud!


In db/seeds.rb, you can write code that will populate the database. Syntax is exactly like the Rails Console, so it should look familiar to you.

Whenever the app is setup on a new machine (your collaborator's, Heroku's servers, etc), 'rake db:seed' can be run, and the database will be populated with the data from seed file. Sweet!


In my db/seeds.rb file, I added this:

Artist.create(name: "Shonen Knife", hometown: "Osaka")
Artist.create(name: "Shakira", hometown: "Barranquilla")
Artist.create(name: "Beyonce", hometown: "Houston")
Artist.create(name: "Teagan and Sara", hometown: "Calgary")


After saving db/seeds.rb, in the terminal run:

$ rake db:seed

After pushing your changes to Heroku, in the terminal run:

$ heroku run rake db:seed


Further Resources Official Ruby documentation
Ruby on Rails Guides Excellent documentation for Rails
Rails Casts Screencasts on how to do almost everything with Rails
The Rails Tutorial Great free (HTML version) book with step-by-step instructions on building Rails apps Listing of all available Gems
Ruby the Hard Way Fun, free (HTML version) book with great information about programming
Girl Develop It Local workshops, events, and coding sessions with awesome people <3