Ruby on Rails - Simpe_Calendar. Visualize the weeks of two in two

1

As you can see in my screenshot, I have a problem with the second week. The days that appear are the same as those of the previous week.

In app / views / calendar / index.html.erb:

<%= week_calendar number_of_weeks: 2 do |date| %>
  <%= date %>
<% end %>

In app / views / simple_calendar / _week_calendar.html.

<div class="simple-calendar">

<!-- Weeks number and arrow for previous and next month-->
<div class="calendar-heading">
  <%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
  <% if calendar.number_of_weeks == 1 %>
    <span class="calendar-title">Week <%= calendar.week_number %></span>
  <%else%>
      <span class="calendar-title">Weeks <%= calendar.week_number %> and <%= calendar.end_week %></span>
  <%end%>
      <%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
</div>
<br>

<!-- Only one week in this line. Week numbers are shown in the first column of the table -->
<!-- <div class="calendar-heading">
  <%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
    <span class="calendar-title">Weeks</span>
  <%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
</div> -->

<%= date_range.slice(0, 7) %> <br>
<%= date_range.slice(7, 14) %> <br>
<%= date_range.class %>

<!-- Table headers -->
  <table class="table table-striped">
    <tbody>
      <% date_range.each_slice(7) do |week| %>
         <thead>
            <tr>
              <th></th>
              <% date_range.slice(0, 7).each do |day| %>
                <th><%= t('date.abbr_day_names')[day.wday] %>
                  <%-# Date relative to the day -%>
                    <%= block.call day, sorted_events.fetch(day, []) %>
                </th>
              <% end %>
            </tr>
          </thead>
        <tr>
        <!-- <td rowspan="2">Week <%= calendar.week_number %></td> -->
        <td>Morning</td>
          <% week.each do |day| %>
            <%-# Buttons -%>
              <%= content_tag :td, class: calendar.td_classes_for(day) do %>
                <span class="button-checkbox">
                  <button type="button" class="btn" data-color="primary">INDISPO</button>
                  <input type="checkbox" class="hidden" />
                </span>
              <% end %>
            <%-# End of block -%>
          <% end %>
        </tr>
        <tr>
        <td>Evening</td>
          <% week.each do |day| %>
            <%-# Buttons -%>
              <%= content_tag :td, class: calendar.td_classes_for(day) do %>
                <span class="button-checkbox">
                  <button type="button" class="btn" data-color="primary">INDISPO</button>
                  <input type="checkbox" class="hidden" />
                </span>
              <% end %>
            <%-# End of block -%>
          <% end %>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>

My problem is in the thead ... I can not make it happen in the second part of the "date" string, the date_range.slice (7, 14).

Any ideas?

Thanks in advance!

    
asked by mrngview 16.05.2017 в 21:45
source

1 answer

1

Your error is not in which you are or not using a helper, it is in that for the header you use the same date_range.slice(0, 7) regardless of what iteration you are in, when you should be using week . In practice, instead of:

          <% date_range.slice(0, 7).each do |day| %>
            <th><%= t('date.abbr_day_names')[day.wday] %>
              <%-# Date relative to the day -%>
                <%= block.call day, sorted_events.fetch(day, []) %>
            </th>
          <% end %>

should be:

          <% week.each do |day| %>
            <th><%= t('date.abbr_day_names')[day.wday] %>
              <%-# Date relative to the day -%>
                <%= block.call day, sorted_events.fetch(day, []) %>
            </th>
          <% end %>
    
answered by 17.05.2017 / 17:04
source