如何为周历自定义表格构建器插件? [英] how to customize the table builder plugin for a week calendar?

查看:43
本文介绍了如何为周历自定义表格构建器插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用表格构建器

<块引用>

https://github.com/p8/table_builder

对于我在这个 Rails 演员表中找到的日历:

<块引用>

http://railscasts.com/episodes/213-calendars.

我的问题是,默认情况下,日历按月显示,但我想按周显示.有谁知道如何自定义日历的显示?这是我的日历视图:

<h2 id="月"><%= 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") %><% calendar_for @statuses, :year =>@date.year, :month =>@date.month 做 |日历|%><%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') %><% calendar.day(:day_method => :date) do |date, statuses|%><%=日期.天%><ul><% 用于状态中的状态 %><li><%=link_to h(status.content), status %></li><%结束%><%结束%><%结束%>

这是控制器:

class CalendarController <应用控制器定义索引do_withs = DoWith.where(:friend_id => current_user.id)@statuses = do_withs.collect { |f|f.status_id }@statuses = @statuses.collect { |f|状态.find(f) }@statuses = @statuses + current_user.statuses@statuses.flatten!@date = params[:month] ?Date.parse(params[:month]) : Date.today结尾结尾

解决方案

设置first_day_of_week: 1,像这样:

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

并相应地调整calendar.head:

<%= calendar.head('星期一', '星期二'...

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

解决方案

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

这篇关于如何为周历自定义表格构建器插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆