Skip to content

Instantly share code, notes, and snippets.

@sjmog
Created September 7, 2018 16:44
Show Gist options
  • Save sjmog/50b9f2456f611dea400587ff33222798 to your computer and use it in GitHub Desktop.
Save sjmog/50b9f2456f611dea400587ff33222798 to your computer and use it in GitHub Desktop.
# 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