你将如何构建这个每天的课程表? [英] How would you build this daily class schedule?

查看:152
本文介绍了你将如何构建这个每天的课程表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是非常简单的,但我试图找到这样做的最好的或最优雅的方式。 Rails应用程序我建立现在必须每天课程安排表。对于每个类相关的对这个问题的领域有:

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:

  • 在本周日
  • 启动时间
  • 结束时间

有一个单一的入口可能是东西,如:

A single entry could be something such as:

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

另外不得不提的是,这是一个双语的Rails 2.2的应用程序,我使用的是原生的i18n Rails的功能。其实,我有几个问题。

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 =>周日)。然后存储的开始时间和结束时间作为时间

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.

  1. 有这样的功能: @sunday_classes = DailyClass.find_sunday_classes 返回所有排序的开始时间的班周日。然后重复为每个天

  1. 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

注:find_by也许应该有ID在最后但这只是preference在你想怎么列命名

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.

这是很基本的。没有什么复杂的。

That's very basic. Nothing complicated.

这篇关于你将如何构建这个每天的课程表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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