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.
$ cd /tmp
$ git clone [email protected]:paulfioravanti/sample_app.git
$ cd sample_app
$ bundle install
$ 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 [email protected]: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
- Added Font Awesome icons to the header
- Added micropost character countdown based on Twitter's
- Added an endless scroll to pages with paginated lists of users or microposts, as shown in Railscast #114 Endless Page (revised)
- 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
- 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
- Internationalized RSpec tests and further refactored them
- Refactored model specs to use shoulda-matchers
- Changed RSpec output to show a progress bar instead of dots using Fuubar
- Swapped out the debug block in the footer for rails-footnotes
- Complete refactoring of test suite to upgrade to Capybara 2.x (see this StackOverflow thread and this StackOverflow thread for the details)
- Performance tested the RSpec test suite and as a result refactored the spec_helper.rb file. See this StackOverflow thread for details.
- Added tests for Globalize3 translations and expanded factories to include a micropost with its relevant translations
- Added service hooks to Travis CI, Rails Brakeman, Gemnasium, Code Climate, Rails Best Practices, Coveralls. See badges under title for details.
- Used SimpleCov to ensure as much test coverage as possible. Currently at 100%.
- Used Bullet to optimize queries
- Added performance monitoring with New Relic
- 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.
- 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.