如何从星期一而不是星期日开始 calendar_for week?
我正在关注 Railscast http://railscasts.com/episodes/213-calendars 并使用安装以下 gem 而不是脚本/插件 https://github.com/jchunky/table_builder
输出很好..向我显示了一个漂亮的日历! (谢谢瑞安) 但我想知道如何修改此代码以使星期从星期一而不是星期日开始显示:
<div id="calendar">
<h2 id="month">
<%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m-%d") %>
<%=h @date.strftime("%B %Y") %>
<%= link_to ">", :month => (@date.end_of_month+1).strftime("%Y-%m-%d") %>
</h2>
<% calendar_for @hours, :year => @date.year, :month => @date.month do |calendar| %>
<%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') %>
<% calendar.day(:day_method => :date) do |date, hours| %>
<%= date.day %>
<ul>
<% for hour in hours %>
<li><%= link_to h(hour.task), hour %></li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
I was following the railscast http://railscasts.com/episodes/213-calendars and I use the following gem instead of script/plugin install
https://github.com/jchunky/table_builder
The output is fine.. displays me a nice calendar! (thanks ryan)
but I would like to know how to modify this code to make the week displayed starting on mondays instead of sundays:
<div id="calendar">
<h2 id="month">
<%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m-%d") %>
<%=h @date.strftime("%B %Y") %>
<%= link_to ">", :month => (@date.end_of_month+1).strftime("%Y-%m-%d") %>
</h2>
<% calendar_for @hours, :year => @date.year, :month => @date.month do |calendar| %>
<%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') %>
<% calendar.day(:day_method => :date) do |date, hours| %>
<%= date.day %>
<ul>
<% for hour in hours %>
<li><%= link_to h(hour.task), hour %></li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看代码,有一个
:first_day_of_week
选项。只需将其设置为 1 = 星期一Looking at the code, there is a
:first_day_of_week
option. Just set it to 1 = Monday您还可以全局设置
Date.beginning_of_week
。You can also set
Date.beginning_of_week
globally.