-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path98-crud.rb
More file actions
37 lines (30 loc) · 790 Bytes
/
98-crud.rb
File metadata and controls
37 lines (30 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'active_record'
require 'pp'
ActiveRecord::Base.establish_connection (
{
:adapter => "mysql2",
:host => "127.0.0.1",
:username => "tacksoo", # change username
:password => "",
:database => "imdb"
}
)
class Actor < ActiveRecord::Base
end
# create, read, update, delete in activerecord
# create a new actor
#actor = Actor.new(id: 1234567, first_name: "Dude", last_name: "Some")
#actor.save
#in one line, Actor.create(id: 12345678, first_name: "Another Dude", last_name: "Cool")
# read new actor
#actor = Actor.find_by id: 1234567
#puts actor.attributes;
# update new actor
#actor = Actor.find_by id: 1234567
#actor.first_name = "Some Dude"
#actor.last_name = "Cool"
#actor.gender = "M"
#actor.save
# delete new actor
#actor = Actor.find_by id: 1234567
#actor.destroy