Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Model review:
- 1) rails new addressbook
- -cd into addressbook
- 2) edit the routes.rb
- root(:to => "pages#index")
- root :to => "pages#index"
- 3) Create corresponding controller#method
- File: pages_controller.rb
- implementation:
- class PagesController < ApplicationController
- def index
- render :template => "pages/index"
- end
- end
- file: app/views/pages/index.html.erb
- table name: contacts
- attributes:
- first_name
- last_name
- email
- contact_number
- #create the migration and model files
- command: rails generate model Contact
- last_name:string email:string
- contact_number:string address:text
- bundle install
- #migrate the migration command into db
- rake db: migrate
- #check db/schema.rb
- 4. add more columns into database
- do not edit db/schema.rb
- rails generate migration add_middle_name_to_contacts
- #in the migratuon under def change
- add_column(:table_name, :field_name, :data_type)
- add_column(:contacts, :middle_name, :string)
- 4.1 add fixture or set of data into our database
- contact = Contact.new
- contact.first_name = "Raphael"
- contact.middle_name = "B"
- contact.last_name = "Alampay"
- contact.email = :raphael.alampay@gmail.com"
- contact.contact_number = "741412"
- contact.save
- 4.2 perform a SELECT statement for only 1 record based on id
- id - 1
- c - Contact.find(id)
- 4.3 perform SELECT all statemetn that returns an arraty of objects
- contacts = Contact.all
- contacts.each do |c|
- puts c.full_name
- end
- 5 display all contacts in root page
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement