开发者

how to customize the table builder plugin for a week calendar?

I'm using a table builder

https://github.com/p8/table_builder

for a calendar that I found in this Rails cast:

h开发者_如何学JAVAttp://railscasts.com/episodes/213-calendars.

My problem is that by default, the calendar is presented by month but I want to present it by week. Does anyone know how to customize the calendar's display? this is my calendar view:

<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 @statuses, :year => @date.year, :month => @date.month do |calendar| %>
    <%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') %>
    <% calendar.day(:day_method => :date) do |date, statuses| %>
      <%= date.day %>
      <ul>
        <% for status in statuses %>
          <li><%= link_to h(status.content), status %></li>
        <% end %>
      </ul>
    <% end %>
  <% end %>
</div>

and this is the controller:

class CalendarController < ApplicationController
  def index
    do_withs = DoWith.where(:friend_id => current_user.id)
    @statuses = do_withs.collect { |f| f.status_id }
    @statuses = @statuses.collect { |f| Status.find(f) }
    @statuses = @statuses + current_user.statuses 
    @statuses.flatten!
    @date = params[:month] ? Date.parse(params[:month]) : Date.today
  end
end


Set first_day_of_week: 1, like this:

<%= calendar_for @statuses, year: @date.year, month: @date.month, first_day_of_week: 1 do |calendar| %>

and adjust calendar.head accordingly:

<%= calendar.head('Monday', 'Tuesday'...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜