Created
September 7, 2018 16:44
-
-
Save sjmog/50b9f2456f611dea400587ff33222798 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
# why do we do this? | |
# (demonstrate working with the object and how nice it is) | |
# (then talk about the idea of different "layers" in software and how we want each "layer" to be self-contained: Ruby in the MVC!) | |
def self.create(url:, title:) | |
return false unless is_url?(url) | |
if ENV['ENVIRONMENT'] == 'test' | |
connection = PG.connect(dbname: 'bookmark_manager_test') | |
else | |
connection = PG.connect(dbname: 'bookmark_manager') | |
end | |
result = connection.exec("INSERT INTO bookmarks (url, title) VALUES('#{url}', '#{title}') RETURNING id, title, url;") | |
Bookmark.new(id: result[0]['id'], title: result[0]['title'], url: result[0]['url']) | |
end | |
attr_reader :id, :title, :url | |
def initialize(id:, title:, url:) | |
@id = id | |
@title = title | |
@url = url | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment