开发者

How to start calendar_for week on Monday instead of Sunday?

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/jchunk开发者_C百科y/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>


Looking at the code, there is a :first_day_of_week option. Just set it to 1 = Monday

calendar_for @hours, :year => @date.year, :month => @date.month, :first_day_of_week => 1 do |calendar|


You can also set Date.beginning_of_week globally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜