hasyrails / calendar-vue-original

0 stars 0 forks source link

55 rails introduces / Railsを導入 #109

Closed hasyrails closed 4 years ago

hasyrails commented 4 years ago

Railsを導入する

hasyrails commented 4 years ago

seedでscheduleデータを作成しても表示されない

seedの設定

# db/seed.rb

require 'time'

start_time = Time.new(2020,9,27)
end_time = Time.new(2020,9,30)

5.times do
  Schedule.create!(
    title: Faker::Book.title,
    start: start_time,
    start_year: start_time.year,
    start_month: start_time.month,
    start_date: start_time.day,
    end: end_time,
    end_year: end_time.year,
    end_month: end_time.month,
    end_date: end_time.day,
  )
end

seed で作成されたデータを確認

$ Schedule.all
  Schedule Load (0.5ms)  SELECT  "schedules".* FROM "schedules" LIMIT ?  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Schedule id: 31, title: "To Your Scattered Bodies Go", start: "2020-09-26 15:00:00", start_year: "2020", start_month: "9", start_date: "27", end: "2020-09-29 15:00:00", end_year: "2020", end_month: "9", end_date: "30", color: nil, commit: nil, created_at: "2020-09-26 23:02:34", updated_at: "2020-09-26 23:02:34">,

表示成功

v-ifの条件で使っているのは文字型ではなく整数型

          <Schedule 
          :schedule="schedule"
          v-for="schedule in schedules"
          v-if="
          schedule.start_date<=day.date
          &&schedule.end_date>=day.date
          &&schedule.start_month===day.month
          "
          :key="schedule.id"
          style="flex:1;min-height:1px;min-width:1px;max-width:230px;text-align: center;margin-bottom:10px;"
          @clickScheduleSettingButton="openScheduleSettingModal"
          >
          </Schedule>

修正

# db/seed.rb

5.times do
  Schedule.create!(
    title: Faker::Book.title,
    start: start_time,
    start_year: start_time.year.to_i,  # integer型へ変換
    start_month: start_time.month.to_i,
    start_date: start_time.day.to_i,
    end: end_time,
    end_year: end_time.year.to_i,
    end_month: end_time.month.to_i,
    end_date: end_time.day.to_i,
  )
end