Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

paulfioravanti/sample_app

Repository files navigation

Ruby on Rails Tutorial: sample application

Build Status Code Climate Coverage Status Security Status

This is the sample application for the Rails 3.2 version of Ruby on Rails Tutorial: Learn Rails by Example by Michael Hartl (plus some modifications).

(I'm not going to be maintaining this version of my Sample App anymore, so please find the Rails 4 version here).

  • This code is currently deployed here using Heroku
  • Translation keys are currently being managed here with Localeapp.

Cloning Locally

$ cd /tmp
$ git clone git@github.com:paulfioravanti/sample_app.git
$ cd sample_app
$ bundle install

Environment Configuration

$ cp config/application.example.yml config/application.yml

Inside Rails App

Generate a secret token:

$ rake secret

Copy the resulting string into the SECRET_TOKEN entry in config/application.yml, along with your database information:

# App keys
SECRET_TOKEN: # your rake secret generated token

development:
  DB_NAME: # your dev db name here
  DB_USER: # your dev db username here
  DB_PASSWORD: # your dev db password here

test:
  DB_NAME: # your test db name here
  DB_USER: # your test db username here
  DB_PASSWORD: # your test db password here

production:
  DB_NAME: # your prod db name here
  DB_USER: # your prod db username here
  DB_PASSWORD: # your prod db password here

Testing with Travis CI

If you're using Travis for continuous integration testing, do the following (without the {{ }}):

Create encrypted travis variables for your Heroku API key and Repo name:

$ gem install travis
$ travis encrypt your_username/your_repo HEROKU_API_KEY={{YOUR_HEROKU_API_KEY}}
$ travis encrypt HEROKU_GIT_URL={{YOUR_HEROKU_GIT_URL}} # eg git@heroku.com:my_app.git
$ travis encrypt DB_NAME={{YOUR_DB_NAME_UNDER_TEST}} # eg: sample_app_test
$ travis encrypt DB_USER={{YOUR_DB_USER}}
$ travis encrypt DB_PASSWORD={{YOUR_DB_PASSWORD}}

Then add them to .travis.yml

env:
  global:
    - secure: {{YOUR_ENCRYPTED_HEROKU_API_KEY}}
    - secure: {{YOUR_ENCRYPTED_HEROKU_GIT_URL}}
    - secure: {{YOUR_ENCRYPTED_DB_NAME_UNDER_TEST}}
    - secure: {{YOUR_ENCRYPTED_DB_USER}}
    - secure: {{YOUR_ENCRYPTED_DB_PASSWORD}}

Deploying with Heroku

Generate production environment variables automatically using Figaro:

$ rake figaro:heroku

Or, do it manually:

$ heroku config:set SECRET_TOKEN={{YOUR_SECRET_TOKEN}}
$ heroku config:set DB_NAME={{YOUR_DB_NAME_UNDER_PRODUCTION}} # eg: sample_app_production
$ heroku config:set DB_USER={{YOUR_DB_USER}}
$ heroku config:set DB_PASSWORD={{YOUR_DB_PASSWORD}}

Localeapp

If you want to use Localeapp to manage language keys in the app (ignore this if you don't), create an account on their site, get an API key, and copy it into the LOCALE_API_KEY entry in config/application.yml, and add the key to your Heroku environment, if you didn't generate it automatically with Figaro:

$ heroku config:set LOCALE_API_KEY={{YOUR_LOCALE_API_KEY}}

New Relic

If you want to use New Relic for app metrics (ignore this if you don't), create an account on their site, get a license key, and copy it into the NEW_RELIC_LICENSE_KEY entry in config/application.yml, and add the key to your Heroku environment, if you didn't generate it automatically with Figaro:

$ heroku config:set NEW_RELIC_LICENSE_KEY={{YOUR_NEW_RELIC_LICENSE_KEY}}

Finally, configure the databases:

$ bundle exec rake db:migrate
$ bundle exec rake db:seed
$ bundle exec rake db:test:prepare RAILS_ENV=test

Modifications:

User Interface

i18n

  • Added locale switcher
  • Internationalized app labels with translations for Japanese and Italian
  • All static content internationalized in Markdown files instead of HTML/ERb files
  • Added i18n-specific routing
  • Added translations to dynamic data and its relevant sample data (microposts) using Globalize3

Backend

  • Moved development database over to Postgresql to match deployment database on Heroku.
  • Changed all views from HTML/ERb to Haml
  • Refactored SCSS files to use more mix-ins, as well as additions to add styling to the language selector
  • Used rails-timeago to do time calculation for microposts on client-side rather than server-side (replaces method calls to time_ago_in_words)
  • Simplified implementation of most forms with SimpleForm
  • Used Figaro to handle all secret keys in an attempt to remove any app-identifiable information from all environments. Reasons why at this StackOverflow thread
  • Moved mass assignment handling over to strong_parameters in anticipation of Rails 4

Testing/Debugging

Reporting/Optimizing

Deployment

  • Fully automatic deployment process put in place: after a commit is pushed to Github, it gets pushed to Travis CI, and then gets deployed directly from the Travis worker to Heroku. See the .travis.yml for details and this StackOverflow thread for reference.

TODOs

  • Tests for Javascript-based functionality: Follow/Unfollow button, micropost countdown, endless scroll
  • Tests for strong_parameters, if an appropriate method gets implemented before Rails 4 is released.

Social

profile for Paul Fioravanti at Stack Overflow, Q&A for professional and enthusiast programmers

endorse

Bitdeli Badge