質問編集履歴
1
コメントいただいたものを直しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
|
25
25
|
> migrationfile
|
26
26
|
|
27
|
-
```
|
27
|
+
```Ruby
|
28
28
|
|
29
29
|
class AddDaysToSchedule < ActiveRecord::Migration[5.2]
|
30
30
|
|
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
> schedule.rb
|
42
42
|
|
43
|
-
```
|
43
|
+
```Ruby
|
44
44
|
|
45
45
|
class Schedule < ApplicationRecord
|
46
46
|
|
@@ -61,3 +61,93 @@
|
|
61
61
|
schdule.rbを下記のserializeを外してみると実際にビルド自体は成功したのですが
|
62
62
|
|
63
63
|
出力する際に、arrayと認識してくれずstringとなってしまうため出力でエラーとなってしまいます。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
### 追記
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
String型に保存して、その後配列に出力することを試みました。
|
72
|
+
|
73
|
+
> migrationfile
|
74
|
+
|
75
|
+
```Ruby
|
76
|
+
|
77
|
+
class AddDaysToSchedule < ActiveRecord::Migration[5.2]
|
78
|
+
|
79
|
+
def change
|
80
|
+
|
81
|
+
add_column :schedules, :days, :string
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
> daysを出力するコード
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
[28] pry(#<EventType>)> self.days
|
96
|
+
|
97
|
+
=> "[0, 1, 2, 3, 4, 5, 6]"
|
98
|
+
|
99
|
+
[29] pry(#<EventType>)> self.days.split('')
|
100
|
+
|
101
|
+
=> ["[",
|
102
|
+
|
103
|
+
"0",
|
104
|
+
|
105
|
+
",",
|
106
|
+
|
107
|
+
" ",
|
108
|
+
|
109
|
+
"1",
|
110
|
+
|
111
|
+
",",
|
112
|
+
|
113
|
+
" ",
|
114
|
+
|
115
|
+
"2",
|
116
|
+
|
117
|
+
",",
|
118
|
+
|
119
|
+
" ",
|
120
|
+
|
121
|
+
"3",
|
122
|
+
|
123
|
+
",",
|
124
|
+
|
125
|
+
" ",
|
126
|
+
|
127
|
+
"4",
|
128
|
+
|
129
|
+
",",
|
130
|
+
|
131
|
+
" ",
|
132
|
+
|
133
|
+
"5",
|
134
|
+
|
135
|
+
",",
|
136
|
+
|
137
|
+
" ",
|
138
|
+
|
139
|
+
"6",
|
140
|
+
|
141
|
+
[30] pry(#<EventType>)> self.days.split
|
142
|
+
|
143
|
+
=> ["[0,", "1,", "2,", "3,", "4,", "5,", "6]"]
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
このやり方は取得したいデータではないのですが、
|
148
|
+
|
149
|
+
文字列で保存して、配列をシリアライズ化する最適な方法はどんなやり方がございますでしょうか。
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
すみませんが、どうぞよろしくお願いいたします。
|