How can I get Sinatra to return a record matching today's date?
-
09-02-2021 - |
Question
My Sinatra app is a collection of notes. Each note is assigned a (future) date when it should be published:
class Note
include DataMapper::Resource
property :id, Serial
property :publish_date, Date
property :content, String
end
I'd like to create a route that will display only today's note, based on the publish_date:
get '/' do
...
erb :today
end
The note I want might be found using note.publish_date.to_s = Date.today.to_s but I can't seem to figure out the syntax to make this work. Thanks in advance for setting be straight!
Solution
Something like
get '/' do
Note.first(:publish_date => Date.today)
erb :today
end
perhaps?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow