Repository navigation
API Setup
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
Cook Cookbook Recipe
------- -------- --------
username cook_id cookbook_id
email name category
password_digest description name
auth_key ingredients
directions
rails new crocker --skip-javascript --database=postgresqlcd crocker
rm -rf app/assets app/views/layouts vendor/assets- Remove assets group
- Uncomment bcrypt-ruby gem
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'pg'
gem 'json'
gem 'bcrypt-ruby', '~> 3.0.0'- bundle
# config/application.rb
config.assets.enabled = falseSince 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 = truebundle exec rails g scaffold --helpbundle exec rails g scaffold Cook username email password_digest auth_key --no-assets --no-stylesheets --no-fixturebundle exec rails g scaffold Cookbook cook_id:integer:index name:index description:index --no-assets --no-stylesheets --no-fixturebundle exec rails g scaffold Recipe cookbook_id:integer:index category name:index ingredients:text directions:text --no-assets --no-stylesheets --no-fixturebundle exec rails g controller Sessions create:post --no-assetsrm app/views/cooks/*.erb app/views/cookbooks/*.erb app/views/recipes/*.erb app/views/sessions/*.erb