你会如何建立这个每日课程表?(How would you build this daily class schedule?)

编程入门 行业动态 更新时间:2024-10-26 08:22:26
你会如何建立这个每日课程表?(How would you build this daily class schedule?)

我想要做的很简单,但我正在努力找到最好或最优雅的方式来做到这一点。 我现在正在构建的Rails应用程序将具有每日课程的时间表。 对于每个类,与此问题相关的字段为:

一周中的天 起始时间 结束时间

单个条目可能是这样的:

星期几:星期三 开始时间:上午10:00 结束时间:中午

此外,我必须提到它是一个双语Rails 2.2应用程序,我正在使用本机i18n Rails功能。 我其实有几个问题。

关于一周中的哪一天,我应该创建一个包含日期列表的额外表格,还是有一种内置的方式来动态创建该列表? 请记住,一周中的这几天必须在日程表视图中以英语或西班牙语呈现,具体取决于区域设置变量。

在查询时间表时,我需要在星期一到星期日的工作日对结果进行分组和排序,当然也可以按照开始时间在每天内订购课程。

关于每个类的开始时间和结束时间,您会使用datetime字段还是整数字段? 如果是后者你将如何实现这一点?

期待阅读你们提出的不同建议。

What I want to do is very simple but I'm trying to find the best or most elegant way to do this. The Rails application I'm building now will have a schedule of daily classes. For each class the fields relevant to this question are:

Day of the week Starting time Ending time

A single entry could be something such as:

day of week: Wednesday starting time: 10:00 am ending time: Noon

Also I must mention that it's a bi-lingual Rails 2.2 app and I'm using the native i18n Rails feature. I actually have several questions.

Regarding the day of the week, should I create an extra table with list of days, or is there a built-in way to create that list on the fly? Keep in mind these days of the week will have to be rendered in English or Spanish in the schedule view depending on the locale variable.

While querying the schedule I will need to group and order the results by weekday, from Monday to Sunday, and of course order the classes within each day by starting time.

Regarding the starting time and ending time of each class would you use datetime fields or integer fields? If the latter how would you implement this exactly?

Looking forward to read the different suggestions you guys will come up with.

最满意答案

我只是将星期几存储为整数。 0 =>星期一... 6 =>星期日(或任何你想要的方式。即0 =>星期日)。 然后将开始时间和结束时间存储为时间。

这将使分组变得非常简单。 您所要做的就是按星期几和开始时间排序。

你可以用多种方式显示它,但这就是我要做的。

具有以下函数: @sunday_classes = DailyClass.find_sunday_classes ,它返回按开始时间排序的星期日的所有类。 然后重复每一天。

def find_sunday_classes find_by_day_of_week(1, :order -> 'start_time') end

注意:find_by可能最后应该有id,但这只是你想要如何命名列的首选项。

如果你想要整整一周,那么从控制器中调用所有七个,并在视图中循环它们。 您甚至可以为每一天创建详细信息页面。

翻译是唯一棘手的部分。 您可以创建一个带整数的辅助函数,并根据本地返回一周中相应日期的文本。

这是非常基本的。 没什么复杂的。

I would just store the day of the week as an integer. 0 => Monday ... 6 => Sunday (or any way you want. ie. 0 => Sunday). Then store the start time and end time as Time.

That would make grouping really easy. All you would have to do is sort by the day of the week and the start time.

You can display this in multiple ways, but here is what I would do.

Have functions like: @sunday_classes = DailyClass.find_sunday_classes that returns all the classes for Sunday sorted by start time. Then repeat for each day.

def find_sunday_classes find_by_day_of_week(1, :order -> 'start_time') end

Note: find_by probably should have id at the end but that's just preference in how you want to name the column.

If you want the full week then call all seven from the controller and loop trough them in the view. You could even create detail pages for each day.

Translation is the only tricky part. You can create a helper function that takes an integer and returns the text for the appropriate day of the week based on local.

That's very basic. Nothing complicated.

更多推荐

Rails,week,时间,time,电脑培训,计算机培训,IT培训"/> <meta name="descriptio

本文发布于:2023-07-15 19:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:你会   课程表   build   schedule   class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!