在Ruby(Sinatra)的一年中, [英] Looping through weeks of the year in Ruby (Sinatra)

查看:138
本文介绍了在Ruby(Sinatra)的一年中,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sinatra和Datamapper创建一个非常简单的分时共享应用程序。申请中的每个用户将有n个保留,并且暂时每个预约从星期一到星期日运行,每星期只能有一个预约。

I'm creating a very simple timeshare application using Sinatra and Datamapper. Every user in the application will have n reservations and for the time being each reservation runs from Monday to Sunday and there can only be one reservation per week.

现在我需要在一年中每个星期的用户将放置姓名(通过自动完成或某事)的文本框(和标签)的视图,从而创建该周的预约。如果保留一周,那么这个名字当然会被填入文本框(并且被禁用)。

Now I will need a view with a textbox (and label) for each week of the year where the users will put their name (through autocompletion or something) and thereby creating a reservation for that week. And if the week is reserved the name will of course be filled in the textbox (and disabled)

这样就像

weeks.each do
  find user that has reserved this week - and create a textbox
end

所以我的问题是简单的 - 如何在Ruby中循环一年的所有星期?

So my question I guess is as simple - how do I loop through all weeks of a year in Ruby?

或者它将是一个更好的解决方案,只需循环52次,并为每个用户创建一个数组保留星期的数组?

Or would it be a better solution to just loop 52 times and make an array for each user with the numbers of reserved weeks in it?

推荐答案

(1..52).each do |week|
   # find user that has reserved this week - and create a textbox
end

这篇关于在Ruby(Sinatra)的一年中,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆