質問編集履歴
2
一部分の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
データベース上には保存ができているのですが表示だけができていない状態です。
|
10
10
|
|
11
|
-
ご教授
|
11
|
+
ご教授いただけると助かります。![イメージ説明](90d6b47d4cb2f9394b013e7afcbcbe99.png)
|
12
12
|
|
13
13
|
|
14
14
|
|
1
記入漏れのため追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -184,13 +184,191 @@
|
|
184
184
|
|
185
185
|
```
|
186
186
|
|
187
|
+
models/schedule.rb
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
class Schedule < ApplicationRecord
|
192
|
+
|
193
|
+
before_save :set_time_zone
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
belongs_to :user
|
198
|
+
|
199
|
+
belongs_to :calendar
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
with_options presence:true do
|
204
|
+
|
205
|
+
validates :date
|
206
|
+
|
207
|
+
validates :schedule_name
|
208
|
+
|
209
|
+
validates :genre_id ,numericality: {other_than: 1}
|
210
|
+
|
211
|
+
validates :user_id
|
212
|
+
|
213
|
+
validates :calendar_id
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
def set_time_zone
|
220
|
+
|
221
|
+
year = self.date.year
|
222
|
+
|
223
|
+
month = self.date.month
|
224
|
+
|
225
|
+
day = self.date.day
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
self.start_time = self.start_time.change(year: year, month: month, day: day)
|
230
|
+
|
231
|
+
self.end_time = self.end_time.change(year: year, month: month, day: day)
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
def start_time
|
238
|
+
|
239
|
+
self.date
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
```
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
scheduleのマイグレーションファイル
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
class CreateSchedules < ActiveRecord::Migration[6.0]
|
258
|
+
|
259
|
+
def change
|
260
|
+
|
261
|
+
create_table :schedules do |t|
|
262
|
+
|
263
|
+
t.references :user, null: false, foreign_key: true
|
264
|
+
|
265
|
+
t.references :calendar, null: false, foreign_key: true
|
266
|
+
|
267
|
+
t.date :date, null: false
|
268
|
+
|
269
|
+
t.string :schedule_name, null: false
|
270
|
+
|
271
|
+
t.integer :genre_id, null: false
|
272
|
+
|
273
|
+
t.time :start_time
|
274
|
+
|
275
|
+
t.time :end_time
|
276
|
+
|
277
|
+
t.text :comment
|
278
|
+
|
279
|
+
t.timestamps
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
```
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
controllers/calendars_controller
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
class CalendarsController < ApplicationController
|
298
|
+
|
299
|
+
before_action :authenticate_user!, only: [:new, :create, :show]
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
def index
|
304
|
+
|
305
|
+
@calendars = Calendar.all
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
def new
|
312
|
+
|
313
|
+
@calendar = Calendar.new
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
def create
|
320
|
+
|
321
|
+
@calendar = Calendar.new(calendar_params)
|
322
|
+
|
323
|
+
if @calendar.save
|
324
|
+
|
325
|
+
redirect_to root_path
|
326
|
+
|
327
|
+
else
|
328
|
+
|
329
|
+
render :new
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
def show
|
338
|
+
|
339
|
+
@calendar = Calendar.find(params[:id])
|
340
|
+
|
341
|
+
@schedules = Schedule.all
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
private
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
def calendar_params
|
352
|
+
|
353
|
+
params.require(:calendar).permit(:calendar_name).merge(user_id: current_user.id)
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
```
|
362
|
+
|
363
|
+
|
364
|
+
|
187
365
|
|
188
366
|
|
189
367
|
### 試したこと
|
190
368
|
|
191
|
-
|
192
|
-
|
193
|
-
|
369
|
+
下記のサイトを参考に作成いたしました。
|
370
|
+
|
371
|
+
[【rails】simple_calendarを使ってカレンダーつきのブログ機能を作ってみた。](https://qiita.com/isaatsu0131/items/ad1d0a6130fe4fd339d0)
|
194
372
|
|
195
373
|
|
196
374
|
|
@@ -198,4 +376,6 @@
|
|
198
376
|
|
199
377
|
|
200
378
|
|
379
|
+
ruby 2.6.5
|
380
|
+
|
201
|
-
|
381
|
+
Rails 6.0.3.5
|