rails new APPNAME --database=postgresql
- Heroku is a popular free hosting service.
- Heroku doesn’t use SQLite3, which is the default database in new Rails apps.
- Why is SQLite incompatible with Heroku?
- SQLite stores the database to a file in your db/ directory.
- PGSQL
-----
### Scaffold post object
- This creates a blog post object with a title and a body.
- The scaffold will generate a lot of files - I've specified the ones I don't want.
- I can always create these files later if needed.
rails g scaffold post title:string text:text --no-assets —no-test-framework --no-helper —no-json
A scaffold will generate the following files:
- Models
- Views
- Controllers
- Tests
- Assets
- Helpers
- Routes
- Active Record Migration File
The -p pretend command shows me what files would be created without actually creating them.
rails g scaffold post title:string text:text --no-assets —no-test-framework --no-helper —no-json
-p
rails g model comment post_id:integer text:text
- Makes model, migration file, and test_unit (2 test files)
rake db:migrate
rails s
rails g controller comments create destroy #creates routes, views, helper, assets, scss, test_unit(2)
================================ To run migration : rails g migration create_posts -p *call with create_posts. not just posts *only creates the migration file, no helpers, models, etc.
================================ scaffold creates: AR — create_posts
Model post.rb
Test Unit For model, controller Resource resources :posts in ApplicationController create posts_controller
ERB For posts, index, edit, show, new, _form
-
Dev Bootcamp recommendation for students: Use model/migration/controller generators only 1x to see the file structure, then only use migration generators for the rest of the phase.
-
My personal recommendation: Use scaffold 4x first.
-
Blog in less than 10 minutes: https://www.youtube.com/watch?v=JaL9ul17kx0 Good, "just do it" introduction to Rails.
-
The difference between generate model vs. resource vs. scaffold http://www.korenlc.com/rails-generate-model-vs-resourse-vs-scaffold/
bundle exec rake routes | grep edit_user_item
http://stackoverflow.com/questions/21708256/no-route-matches-missing-required-keys-id