質問編集履歴
3
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,7 +45,7 @@
|
|
45
45
|
```Ruby
|
46
46
|
#controller
|
47
47
|
def schedule_params
|
48
|
-
params[:
|
48
|
+
params[:schedule][:start_datetime] = (params[:schedule][:start_date] + ' ' + params[:schedule][:start_time]).to_s
|
49
49
|
params.require(:schedule).permit(...
|
50
50
|
end
|
51
51
|
```
|
2
回答を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -40,3 +40,29 @@
|
|
40
40
|
<%= form.text_field :start_day_accessor, value: @schedule.start_datetime.nil? ? '' : @schedule.start_datetime.strftime("%Y-%m-%d") %>
|
41
41
|
<%= form.select :start_time_accessor, options_for_select(time_array_for_select, @schedule.start_datetime.nil? ? '' : @schedule.start_datetime.strftime("%H:%M")) %>
|
42
42
|
```
|
43
|
+
|
44
|
+
### 下記にて解決しました。
|
45
|
+
```Ruby
|
46
|
+
#controller
|
47
|
+
def schedule_params
|
48
|
+
params[:user][:start_datetime] = (params[:user][:start_date] + ' ' + params[:user][:start_time]).to_s
|
49
|
+
params.require(:schedule).permit(...
|
50
|
+
end
|
51
|
+
```
|
52
|
+
```Ruby
|
53
|
+
#view
|
54
|
+
<%= form.text_field :start_date %>
|
55
|
+
<%= form.text_field :start_time %>
|
56
|
+
```
|
57
|
+
```Ruby
|
58
|
+
#model
|
59
|
+
class Schedule < ApplicationRecord
|
60
|
+
def start_date
|
61
|
+
start_datetime.strftime("%Y-%m-%d") if start_datetime.present?
|
62
|
+
end
|
63
|
+
|
64
|
+
def start_time
|
65
|
+
start_datetime.strftime("%H:%M") if start_datetime.present?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
1
誤字修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提
|
2
2
|
|
3
|
-
DBに
|
3
|
+
DBにstart_datetimeというカラムがありDatetimeクラスで保存しています。
|
4
4
|
その年月日を保存・取り出すためにstart_day_accessor、時間を保存・取り出すためにstart_time_accessorを準備しています。
|
5
5
|
```Ruby
|
6
6
|
class Schedule < ApplicationRecord
|