Skip to content
Mike Bradford edited this page May 25, 2012 · 1 revision

As an example, let's build a cookbook app to store and share recipes. We'll name it Crocker

Data model

Cook              Cookbook      Recipe          
-------           --------      --------        
username          cook_id       cookbook_id     
email             name          category
password_digest   description   name
auth_key                        ingredients
                                directions

Build new rails app

rails new crocker --skip-javascript --database=postgresql

Remove asset and layout directories

cd crocker
rm -rf app/assets app/views/layouts vendor/assets

Update Gemfile

  1. Remove assets group
  2. Uncomment bcrypt-ruby gem
source 'https://rubygems.org'

gem 'rails', '3.2.3'
gem 'pg'
gem 'json'
gem 'bcrypt-ruby', '~> 3.0.0'
  1. bundle

Disable the asset pipeline

# config/application.rb
config.assets.enabled = false

Force SSL in production

Since our mobile app sends the sensitive auth_key with most requests to the API, we want to pass that in a secure fashion. If any outsider acquires that key, they would have complete access to the user account.

# config/environments/production.rb
config.force_ssl = true

Generate scaffolds

bundle exec rails g scaffold --help
bundle exec rails g scaffold Cook username email password_digest auth_key --no-assets --no-stylesheets --no-fixture
bundle exec rails g scaffold Cookbook cook_id:integer:index name:index description:index --no-assets --no-stylesheets --no-fixture
bundle exec rails g scaffold Recipe cookbook_id:integer:index category name:index ingredients:text directions:text --no-assets --no-stylesheets --no-fixture
bundle exec rails g controller Sessions create:post --no-assets

Remove ERB files from view directories

rm app/views/cooks/*.erb app/views/cookbooks/*.erb app/views/recipes/*.erb app/views/sessions/*.erb

Clone this wiki locally