hasyrails / calendar-vue-demo

0 stars 0 forks source link

01 calendar display / カレンダー表示 #1

Open hasyrails opened 4 years ago

hasyrails commented 4 years ago

カレンダーを表示させる

実装参考 jsとかややこしいの使わずRailsでカスタム自由度の高いカレンダー実装

rails g controller calendar
hasyrails commented 4 years ago

@calendar_days

jsとかややこしいの使わずRailsでカスタム自由度の高いカレンダー実装

で、次に@calendar_daysに突っ込む値です

@calendar_daysはどうすれば良いの?? となった

実装

def index
  @calendar_days = get_calendar_dates(Date.today)
end

##  以下、参考そのまま 

def get_calendar_dates(date)
  ‥
end

def get_pre_shortage_days(date)
  ‥
end

def get_post_shortage_days(date)
  ‥
end
hasyrails commented 4 years ago

calendar/index.html.erb

参考そのまま

<div class="event-calendar">
    <table>
        <caption>2016年9月</caption>
        <tbody>
            <tr>
                <th>日</th>
                <th>月</th>
                <th>火</th>
                <th>水</th>
                <th>木</th>
                <th>金</th>
                <th>土</th>
            </tr>
            <% @calendar_days.each_with_index do |day, i| %>
                <% if i == 0 || i % 7 == 0 %>
                    <tr>
                <% end %>
                <td>
                    <p>
                        <%= day %>
                    </p>
                    <div>
                        <!-- ここにカレンダー1日単位で情報埋める -->
                    </div>
                </td>
                <% if i !=  0 && (i + 1) % 7 == 0 %>
                    </tr>
                <% end %>
            <% end %>
        </tbody>
    </table>
</div>
hasyrails commented 4 years ago

routes.rb

Rails.application.routes.draw do
+  resources :calendar
end
hasyrails commented 4 years ago

Image from Gyazo