使用 Sinatra 制作日历
好吧,我实际上不想制作日历,但我需要一年中每一天的视图,我想这有点相同。假设我有一个视图,您可以在页面顶部看到“7 月 1 日”,并且您可以链接到前一天和后一天。在其下方有一个房间列表(在我的示例中),它们具有不同的状态 - 可用或保留。
我如何使用 Sinatra 和 Datamapper 制作这样的东西?我是否将其放在网址中或者我有什么可能性?
get '/rooms/:date' do
"List of rooms for " + params[:date]
end
所以回顾一下。我正在尝试创建一个日历,每天您都会获得一个列表,其中列出了一年中每一天可用或保留的状态 - 但我不知道从哪里开始。
Well I don't actually want to make a calendar but I need a view for each day of the year which I guess is sort of the same. Say I have a view where you see e.g. "July 1st" in the top of the page and you have links to the day before and the day after. Beneath this there is a list of - in my example - rooms and they have different states - either available or reserved.
How could I make something like this using Sinatra and Datamapper? Do I put it in the url or what possibilities do I have?
get '/rooms/:date' do
"List of rooms for " + params[:date]
end
So to recap. I'm trying to create a calendar where for each day you get a list of something that has a state of either available or reserved for every day of the year - but I don't know where to start.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将从数据库设计开始。你的中央桌子是什么?他们如何合并时态数据?假设您有
房间
列表。然后,您必须有另一个表(例如room_reservations
),每个记录都有start_date
、end_date
和room_id
。查找特定日期入住的房间列表的查询应该是微不足道的。至于在 Sinatra 中实现以日期为中心的视图,可以很简单:
I'd start with database design. What are your central tables? How do they incorporate temporal data? Let's say you have list of
rooms
. Then you would have to have another table (sayroom_reservations
), each record havingstart_date
,end_date
androom_id
. A query looking for a list of rooms occupied on a certain date should be trivial.As for implementing date-centric view in Sinatra, it can be as simple as: