タイムカードの作成のために、日付と曜日が付いた表を作っていて、9月の分はしっかり1日から30日まで取得でき安心していたら
今日になって10月なのに10月分に更新されなかったので困っています。
考えたこと
・インスタンス変数に代入する前までは正しく取得出来ているか?
→取得出来ている
・application.rbのタイムゾーンをconfig.time_zone = 'Tokyo'
に変えてサーバー落として再起動してみた。
→変化なし
なのでviewに受け渡す時になんかおかしいようです。
これがなぜか分からないので教えて欲しいです。よろしくお願いいたします。
controller
ruby
1class TimeCardsController < ApplicationController 2 def index 3 #月初と月末を求る 4 require 'date' 5 day = Date.today 6 start_date = Date::new(day.year,day.month, 1) 7 end_date = start_date >> 1 8 end_date = end_date - 1 9 @start_date = start_date 10 @end_date = end_date 11 #今何年の取得 12 year_name = start_date.year 13 @year_name = year_name 14 #今何月の取得 15 month_name = start_date.month 16 @month_name = month_name 17 end 18 19 def show 20 21 end 22 23 def create 24 25 end 26 27end 28
VIEW
ruby
1<div class="container"> 2 <h1><%= @year_name %>年<%= @month_name %>月の勤務表</h1> 3<table class="table"> 4 <thead> 5 <tr> 6 <th>日付</th> 7 <th>曜</th> 8 <th>出社時間</th> 9 <th>退社時間</th> 10 <th>勤務時間</th> 11 </tr> 12 </thead> 13 <%(Date.parse("#{@start_date}")..Date.parse("#{@end_date}")).each do |date| %> 14 <tr> 15 <td><%="#{date.month}月#{date.day}日"%></td> 16 <td><%= %w[日 月 火 水 木 金 土][date.wday] %></td> 17 <td></td> 18 <td></td> 19 <td></td> 20 </tr> 21 <%end%> 22</table> 23</div>
root
ruby
1Rails.application.routes.draw do 2 devise_for :users 3 root 'comments#index' 4 get 'comments/index' 5 6 7 root to:"users#index" 8 get "/employees_index", to:"employees#index" 9 get "/employees_new", to:"employees#new" 10 post "/employees_create", to:"employees#create" 11 delete "/employees/:id", to:"employees#destroy" 12 get "employees/:id/edit", to:"employees#edit" 13 patch "/employees/:id", to:"employees#update" 14 15 16 17 18 get '/timecard', to: 'time_cards#show' 19 post '/timecard/create', to: 'time_cards#create' 20 get '/monthly', to: 'time_cards#index' 21end 22
application.rb
ruby
1require_relative 'boot' 2 3require 'rails/all' 4 5# Require the gems listed in Gemfile, including any gems 6# you've limited to :test, :development, or :production. 7Bundler.require(*Rails.groups) 8 9module Progress13 10 class Application < Rails::Application 11 # Settings in config/environments/* take precedence over those specified here. 12 # Application configuration should go into files in config/initializers 13 # -- all .rb files in that directory are automatically loaded. 14 config.time_zone = 'Tokyo' 15 end 16end 17
回答2件
あなたの回答
tips
プレビュー