指定两个月之间距离的铁路迁移..?
我想做两个下拉菜单。开始时间和结束时间。具体来说,我只需要几个月。例如,我想选择一月,然后选择三月,然后让数据库读取到这是这两个月加上二月。
有没有可行的开箱即用的迁移?
我猜..
脚本/生成迁移 AddMonthsToClass beginDate:datetime #through endDate:datetime
如果我的问题听起来迟钝,我提前道歉!对不起! :D
I would like to make two drop downs. a start time, and an end time. Specifically, I only need months. I would like to, for example, choose January, and then March, and then have the database read that it is the these two months plus February.
Is there any out of the box migration that could work?
I'm guessing..
script/generate migration AddMonthsToClass beginDate:datetime #through endDate:datetime
I apologize ahead of time if my question sounds retarded! Sorry! :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能会对您有所帮助: http://www.francisfish.com/getting_the_number_of_months_ Between_two_dates_in_rubyrails.htm
获取月份数,您可以从中获取月份名称:
例如
月[时间.现在.月, 5]
=> [“五月”、“六月”、“七月”、“八月”、“九月”]
编辑:
相反,您可以使用:
编辑:
或者,如果您在选择标签中获取月份数字,则可以使用:
但是,如果 end_month_num 小于 start_month_num 这将失败这
应该有效:
This may help you: http://www.francisfish.com/getting_the_number_of_months_between_two_dates_in_rubyrails.htm
After you get the number of months, you can get the month names from this:
eg
months[Time.now.month, 5]
=> ["May", "June", "July", "August", "September"]
edit:
Instead of that, you can use:
edit:
Or if you get the month numbers in your select tag, you can just use:
but, this would fail if end_month_num is less than start_month_num
This should work: