This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asdklfjdlsaf | |
asdfkljasd | |
asdfkhadsf | |
adsf | |
asd | |
f | |
asdf | |
asdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ruby: | |
def save | |
sql = "INSERT INTO users (name, age) VALUES (?, ?)" | |
DB[:conn].execute(sql, self.name, self.age) | |
@id = DB[:conn].execute("SELECT last_insert_rowid() FROM users")[0][0] | |
end | |
user = User.new(name: "Tom", age: 26) | |
user.save | |
#Active Record: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ruby | |
class User | |
def initialize (id = nil, name, grade) | |
self.name = name | |
self.grade = grade | |
@@all << self | |
end | |
def self.all | |
@all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ruby | |
def self.new_from_db(row) | |
new_student = self.new(row[1],row[2]) | |
new_student.id = row[0] | |
new_student | |
end | |
def self.find_by_name(name) | |
sql = "SELECT * FROM users WHERE name = ?" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ruby | |
def self.delete_by_name(name) | |
sql = "DELETE FROM users WHERE name = ?" | |
DB[:conn].execute(sql,name) | |
end | |
#Active Record | |
user = User.find_by(name: 'David') | |
user.destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@vowels = %w{a e i o u} | |
def piglatinize(name) | |
letters_array = name.split("") | |
first_letter = letters_array[0] | |
first_cons = [] | |
if !@@vowels.include?(first_letter.downcase) | |
first_cons << letters_array.shift until @@vowels.include?(letters_array[0]) | |
letters_array += first_cons | |
end | |
@@vowels.include?(first_letter.downcase) ? letters_array << "way" : letters_array << "ay" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.find(10) | |
=> #<User id: 10, name: => "Tom"> | |
User.find(1, 10) #or ([1, 10]) | |
=> #[<User id: 1, name: => "Lifo">, #<User id: 10, name: => "Ryan">] | |
User.first | |
User.last | |
User.all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
after_initialize :starting_balance | |
def starting_balance | |
self.balance ||= 100 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<div id="clockdiv"></div> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1"> | |
<title>Multiple Galleries</title> | |
<!-- CSS--> | |
<link rel="stylesheet" href="main.css"> | |
<!-- END CSS --> |
OlderNewer