Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

ruby on rails - 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:

http://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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...