Code Monkey home page Code Monkey logo

sample_app's Introduction

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 [email protected]: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 [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

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

sample_app's People

Contributors

bitdeli-chef avatar paulfioravanti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.