Skip to main content

Rails Chops: Working with databases

References

Objectives

  • Configure Rails to work with a database (database.yml)

  • create table (migration)

  • use ActiveRecord to interact with our database

  • use script/console to learn how ActiveRecord works

Model

  • handle application state (usually in the database)

  • encapsulate business logic, such as data validation and rules applied to data

ActiveRecord

  • ORM (object-relational mapping)

  • Instead of dealing with database through SQL statements, ORM layer presents records as a collection of objects

  • Table represents a collection of objects(stories)

  • Record represents an object/model (story)

  • Field represents an object attribute (title)

CRUD operations on database

  • C: create, insert record into table

  • R: read, select record(s) from table

  • U: update, update record(s) in the table

  • D: delete, delete record(s) from the table

Comments

Popular posts from this blog

Setting up Sinatra and DataMapper on Windows

I use a MacBook Pro for work and pleasure on a day-to-day basis. Recently, I was asked to teach web students at a local high school. These students know html/graphics/flash/etc. The advanced students were ready for some server-side programming and database integration. I wanted the students to be able to get up and going quickly (for motivation reasons) and to create useful apps (using a database). I felt Sinatra to be a great fit for this. I created a Sinatra app for my uncle and his business. It was a joy to work with it and I was able to deploy quickly using Heroku . My experience of using Sinatra on my Mac was straightforward. Like most things using Ruby and Mac: it just worked. However, I found out the students at the high school use MS Windows. Fortunately, I have a Windows XP virtual machine running in VMWare so I could prepare that way. I used to teach computer science and web development at Spokane Community College and am aware of teaching Ruby in a Windows lab environm

PHP and Laravel Development: A 17-part video series

 Enjoy!

Beginning Erlang for Ruby Developers

If you missed my "Beginning Erlang for Ruby Developers" here is a link to the presentation. https://beg-erlang-for-ruby-devs.herokuapp.com/