如何更改simple_calendar宝石的日期

时间:2018-08-21 20:57:49

标签: ruby-on-rails

我正在使用simple_calendar在Rails中创建日历。

enter image description here

但是,日历的日期在图像中显示为2018-08-23。

我想逐日显示日历上的日期,例如23,而不是2018-08-23。

_month_calendar.html.erb

<div class="simple-calendar">
  <div class="calendar-heading">
    <%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
    <span class="calendar-title"><%= t('date.month_names')[start_date.month] %> <%= start_date.year %></span>
    <%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
  </div>

  <table class="table table-striped">
    <thead>
      <tr>
        <% date_range.slice(0, 7).each do |day| %>
          <th><%= t('date.abbr_day_names')[day.wday] %></th>
        <% end %>
      </tr>
    </thead>

    <tbody>
      <% date_range.each_slice(7) do |week| %>
        <tr>
          <% week.each do |day| %>
            <%= content_tag :td, class: calendar.td_classes_for(day) do %>
              <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(block) %>
                <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
              <% else %>
                <% block.call day, sorted_events.fetch(day, []) %>
              <% end %>
            <% end %>
          <% end %>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

1 个答案:

答案 0 :(得分:0)

根据the documentation,您必须在day对象上调用date

在您的情况下,我假设date对象是一个名为day的对象,因此您必须在视图中更改2行(if/else语句内的那些行):

<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(block) %>
  <% capture_haml(day.day, sorted_events.fetch(day, []), &block) %>
<% else %>
  <% block.call day.day, sorted_events.fetch(day, []) %>
<% end %>