使用 Sinatra 制作日历

发布于 2024-09-09 04:05:18 字数 354 浏览 0 评论 0原文

好吧,我实际上不想制作日历,但我需要一年中每一天的视图,我想这有点相同。假设我有一个视图,您可以在页面顶部看到“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-09-16 04:05:18

我将从数据库设计开始。你的中央桌子是什么?他们如何合并时态数据?假设您有房间列表。然后,您必须有另一个表(例如 room_reservations),每个记录都有 start_dateend_dateroom_id。查找特定日期入住的房间列表的查询应该是微不足道的。

至于在 Sinatra 中实现以日期为中心的视图,可以很简单:

require 'rubygems'
require 'sinatra'
require 'date'
require 'haml'

get '/' do
  redirect "/rooms/#{Date.today}"
end

get '/rooms/:date' do |d|
  @date = Date.parse d
  haml :rooms
end

__END__

@@rooms
%a{:href => "/rooms/#{@date - 1}"}
  =@date-1
%span
  =@date
%a{:href => "/rooms/#{@date + 1}"}
  =@date+1

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 (say room_reservations), each record having start_date, end_date and room_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:

require 'rubygems'
require 'sinatra'
require 'date'
require 'haml'

get '/' do
  redirect "/rooms/#{Date.today}"
end

get '/rooms/:date' do |d|
  @date = Date.parse d
  haml :rooms
end

__END__

@@rooms
%a{:href => "/rooms/#{@date - 1}"}
  =@date-1
%span
  =@date
%a{:href => "/rooms/#{@date + 1}"}
  =@date+1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文