Saturday 10 March 2012

Rails study notes 1

Rails as as MVC fraework
model view controller
controller(models.rb) rails routing

1. Routes map incoming url's to controller actions
2. controller actions set instance vairables, visible to views
3. controller action enventually renders a view

Convention over configuration: if naming follows certain conventions, no need for config files
Don't repear yourself: mechanisms to exract common functionality


Database:
Rails feature:
Testing: develpment and production and test enviroments each have own DB
Mirgration: scripts to descripe the change

up version and down version of migration methods, that makes everything reversible
Apply migration to development:
rake db:migrate

Add a new model
rails generate migration

Raisl generate sql statement at runtime, based on ruby code


Subclassing from ActiveRecord::Base
connects a model to a database


Reading things in the database
Movie.where("rating = 'PG')


Add a action
1. create route in config/routes.rb
2. Add the action in the apporcatia place
3. add the view coresspondinly


Debug
Printing to termial
log file

when debugging, the error information can be very useful, the information could tell us where th error is in the ruby.
Don't use puts or printf to print error message, as they may just been print out on the terminal, and the information will lost forever

No comments:

Post a Comment