Ruby on Rails Introduction

1,015 views

Published on

Ruby on Rails introduction.

Published in: Software, Technology
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,015
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
24
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Ruby on Rails Introduction

  1. 1. Ruby on Rails
  2. 2. Introduction to Ruby Ruby Syntax and Concepts Variables Constants Blocks Hashes
  3. 3. Creating active record user = User.create(name: "David", occupation: "Code Artist") user = User.new user.name = "David" user.occupation = "Code Artist"  user.save
  4. 4. Reading an activerecord from database users = User.all user = User.first david = User.find_by(name: 'David') users = User.where(name: 'David', occupation: 'Code Artist').order('created_at DESC')
  5. 5. Updating Activerecords attributes user = User.find_by(name: 'David') user.update(name: 'Dave') Destroying an ActiveRecors user = User.find_by(name: 'David') user.destroy
  6. 6. Validation  create  create!  save  save!  update  update!
  7. 7. Validation Helpers Acceptance class Person < ActiveRecord::Base  validates :terms_of_service, acceptance: true end validates_associated class Library < ActiveRecord::Base  has_many :books  validates_associated :books end
  8. 8. Length class Person < ActiveRecord::Base  validates :name, length: { minimum: 2 }  validates :bio, length: { maximum: 500 }  validates :password, length: { in: 6..20 }  validates :registration_number, length: { is: 6 } end Uniqueness class Account < ActiveRecord::Base  validates :email, uniqueness: true end
  9. 9. Order and list of Model Call Backs
  10. 10. Assocaiations class Customer < ActiveRecord::Base end  class Order < ActiveRecord::Base end @order = Order.create(order_date: Time.now, customer_id: @customer.id)
  11. 11. class Customer < ActiveRecord::Base  has_many :orders, dependent: :destroy end  class Order < ActiveRecord::Base  belongs_to :customer end @order = @customer.orders.create(order_date: Time.now)
  12. 12. belongs_to class Order < ActiveRecord::Base  belongs_to :customer end
  13. 13. has_one :through
  14. 14. has_many :
  15. 15. The has_and_belongs_to_many Association:
  16. 16. Controller
  17. 17. CRUD, Verbs, and Actions

×