Created
October 17, 2016 13:34
-
-
Save thomasmarren/7991c5e1f61007bd8356f52b5fb181ca to your computer and use it in GitHub Desktop.
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: | |
user = User.create(name: "Tom", age: 26) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment