11.09.2013

Rails Cheat Sheet

1. Create rails application
$ rails new demo
2. Examine installation
$ cd demo
$ rake about
3. Start the application
$ rails server
4. Create a controller and actions
$ rails generate controller Say hello goodbye
$ rails generate controller Store index
5. Generate a scaffold
$ rails generate scaffold Product title:string description:text image_url:string price:decimal
$ rails generate scaffold_controller LdapUsers  # generate only controller and views, say if model had been predefined.
With relationships
$ rails generate scaffold LineItem product:references cart:belongs_to
Destroy just created scaffold
$ rails destroy scaffold LineItem
6. Apply the migration
$ rake db:migrate
7. Run the tests
$ rake test
$ rake test:models - only the models directory
8. Populate table with test data
$ rake db:seed
9. Rollback the migration
$ rake db:rollback
10. Open up rails console
$ rails console
$ rails c
11. Add a column to a table
$ rails generate migration add_quantity_to_line_items quantity:integer
12. Create a migration
$ rails generate migration combine_items_in_cart
13. Clear the logs
$ rake log:clear LOGS=test
14. Create a mailer
$ rails generate mailer OrderNotifier received shipped
15. Create an integration test
$ rails generate integration_test user_stories
16. Generate documentation in HTML format. First modify README.doc then...
$ rake doc:app
17. See how much code is written
$ rake stats
18. Loading production db
$ rake db:setup RAILS_ENV="production"
19. Generate rake task
$ rails g task perfdb get_baselines
      create  lib/tasks/perfdb.rake

No comments:

Post a Comment