Datamodel in Ruby

  • 3,121 views
Uploaded on

A short presentation followed by a demo (not included) of the capabilities of Ruby on Rails for databases.

A short presentation followed by a demo (not included) of the capabilities of Ruby on Rails for databases.

More in: Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Exceptional slideshow. Very clear and helpful
    Sharika
    http://winkhealth.com http://financewink.com
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,121
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
1
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Building your app (1)
    • Modeling the data
    Raymond van Dongelen | NHL | www.webxy.nl
  • 2. Datamodel
    • Should prevent storing the same information twice
    • Should guard relations in the data
    • Should be able to cope with changing data structure
  • 3. Contents
    • Datamodel
    • ActiveRecord
    • Sample application
  • 4. Ruby and data
    • All database handling is done in the model
    • Powerful features to validate data, guard relations, search data.
    • All data is wrapped in Ruby classes
    • SQL is almost never needed
  • 5. Ruby naming
    • Table name plural
    • Key in a table “id”
    • Reference to another table “table_id”
  • 6. ActiveRecord(1)
    • Validators:
    • validates_presence_of
    • validates_uniqueness_of
    • Relations:
    • belongs_to
    • has_one
    • has_and_belongs_to_many
    • has_many
  • 7. ActiveRecord(2)
    • Example:
    • class Agenda < ActiveRecord::Base
    • belongs_to :user
    • validates_presence_of :user, :message => &quot;cannot be empty&quot;
    • end
  • 8. ActiveRecord (3)
    • @agenda = Agenda.find(1)
    • puts (@agenda.user.name)
    • <== We are able to display the user, it is automatically fetched
  • 9. ActiveRecord (4)
    • Dynamic find
    • Agenda.find_all_name (“Home”)
    • User.find_all_by_email (“ [email_address] ”)
  • 10. ActiveRecord (5)
    • Many many powerful features
    • Read chapter 14 agile web development with Ruby on Rails
  • 11. Sample application User Project Task Subtask User can be in many projects Project can have many users A project has many tasks A task has many subtasks Sample can be found on http://www.webxy.nl/?p=63