Giter Club home page Giter Club logo

sample_app_rails_4's Introduction

Ruby on Rails Tutorial: sample application

Build Status Dependency Status Code Climate Coverage Status Security Status

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

(Rails 3.2 version here)

  • This code is currently deployed here using Heroku

Cloning Locally

$ cd /tmp
$ git clone [email protected]:paulfioravanti/sample_app_rails_4.git
$ cd sample_app_rails_4
$ bundle install

Environment Configuration

Secret information configuration

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

Generate a secret key:

$ rake secret

Copy the resulting string into the SK entry in config/application.yml, along with your database information for all environments:

# App keys
SK: # your rake secret generated token

development:
  DB_NAME_DEV: # your dev db name here
  DB_USER_DEV: # your dev db username here
  DB_PASSWORD_DEV: # your dev db password here

test:
  DB_NAME_TEST: # your test db name here
  DB_USER_TEST: # your test db username here
  DB_PASSWORD_TEST: # your test db password here

production:
  DB_NAME_PROD: # your prod db name here
  DB_USER_PROD: # your prod db username here
  DB_PASSWORD_PROD: # your prod db password here

HEROKU_API_KEY: # your Heroku api key here
HEROKU_APP_NAME: # your Heroku app name here
ROLLBAR_ACCESS_TOKEN: # your Rollbar access token here

Note: rake secret generates a key of 128 characters. Use 114 of those characters if you want to use the secret_key_base as a secure config variable in your Travis build.

Deploying with Heroku

After creating the Heroku repo, generate production environment variables automatically using Figaro:

$ rake figaro:heroku RAILS_ENV=production

Or, do it manually:

$ heroku config:set SK={{YOUR_SECRET_KEY_BASE}}
$ heroku config:set DB_NAME={{YOUR_DB_NAME_UNDER_PRODUCTION}} # eg: my_app_production
$ heroku config:set DB_USER={{YOUR_DB_USER}}
$ heroku config:set DB_PASSWORD={{YOUR_DB_PASSWORD}}

Let Heroku compile assets to avoid doing it locally (optional, as the functionality is experimental):

$ heroku labs:enable user-env-compile -a {{YOUR_HEROKU_APP_NAME}}
# May not need this if compiling Heroku slug on Travis...

Continuous Integration/Deployment 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 SK={{YOUR_SECRET_KEY_BASE_OF_114_CHARS_OR_LESS}} --add
$ travis encrypt DB_NAME={{YOUR_DB_NAME_TEST}} --add # eg: my_app_test
$ travis encrypt DB_USER={{YOUR_DB_USER_TEST}} --add
$ travis encrypt DB_PASSWORD={{YOUR_DB_PASSWORD_TEST}} --add
$ travis encrypt DB_NAME={{YOUR_DB_NAME_PROD}} --add # eg: my_app_test
$ travis encrypt DB_USER={{YOUR_DB_USER_PROD}} --add
$ travis encrypt DB_PASSWORD={{YOUR_DB_PASSWORD_PROD}} --add
$ travis encrypt HEROKU_API_KEY={{YOUR_HEROKU_API_KEY}} --add
$ travis encrypt HEROKU_APP_NAME={{YOUR_HEROKU_APP_NAME}} --add # eg my_app
$ travis encrypt ROLLBAR_ACCESS_TOKEN={{YOUR_ROLLBAR_ACCESS_TOKEN}} --add

Or, without the --add flag, you can add them manually to .travis.yml

env:
  global:
  - secure: {{YOUR_ENCRYPTED_SECRET_KEY_BASE_OF_114_CHARS_OR_LESS}}
  - secure: {{YOUR_ENCRYPTED_DB_NAME_TEST}}
  - secure: {{YOUR_ENCRYPTED_DB_USER_TEST}}
  - secure: {{YOUR_ENCRYPTED_DB_PASSWORD_TEST}}
  - secure: {{YOUR_ENCRYPTED_DB_NAME_PROD}}
  - secure: {{YOUR_ENCRYPTED_DB_USER_PROD}}
  - secure: {{YOUR_ENCRYPTED_DB_PASSWORD_PROD}}
  - secure: {{YOUR_ENCRYPTED_HEROKU_API_KEY}}
  - secure: {{YOUR_ENCRYPTED_HEROKU_APP_NAME}}
  - secure: {{YOUR_ROLLBAR_ACCESS_TOKEN}}

Finally, configure the databases:

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

Issues

I haven't yet been able to get the following functionality that worked in Rails 3 to work in Rails 4:

  • Micropost character countdown based on Twitter's
  • The endless scroll to pages with paginated lists of users or microposts, as shown in Railscast #114 Endless Page (revised)
  • It seems rails-timeago currently is not compatible with Rails 4, so time calculation for microposts have reverted back to the default time_ago_in_words

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
  • 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

Testing/Debugging

  • Completely re-wrote test suite to use expect syntax exclusively due to plans to depreciate should syntax, as well as write feature tests in (hopefully) a more user-friendly way.
  • 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
  • Added tests for Globalize3 translations and expanded factories to include a micropost with its relevant translations

Reporting/Optimizing

  • Used SimpleCov to ensure as much test coverage as possible.
  • Used Bullet to optimize queries

Other

  • Travis can only encrypt a string of total length of 117 characters, including the name of the variable, which is less than the 128 character string that rake secret generates. It's convenient to be able to pass the secret_key_base directly to Travis and have Travis use it to compile a Heroku slug to deploy, but I'm uncertain as to realistically how much less secure a 114 character key (SK={KEY}) is versus a 128 character key

Social

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

endorse

Bitdeli Badge

sample_app_rails_4's People

Contributors

paulfioravanti avatar bitdeli-chef avatar

Watchers

Patricia Martinez-Aceves 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.