質問編集履歴
6
modelについて変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,6 +154,14 @@
|
|
154
154
|
|
155
155
|
accepts_nested_attributes_for :hashtag, :restaurant
|
156
156
|
|
157
|
+
|
158
|
+
|
159
|
+
def hashtag
|
160
|
+
|
161
|
+
Hashtag.new
|
162
|
+
|
163
|
+
end
|
164
|
+
|
157
165
|
end
|
158
166
|
|
159
167
|
```
|
5
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,31 +64,11 @@
|
|
64
64
|
|
65
65
|
create_table "hashtags", force: :cascade do |t|
|
66
66
|
|
67
|
-
t.
|
67
|
+
t.integer "couple"
|
68
|
-
|
68
|
+
|
69
|
-
t.
|
69
|
+
t.integer "firstdate"
|
70
|
-
|
71
|
-
|
70
|
+
|
72
|
-
|
73
|
-
t.boolean "confession"
|
74
|
-
|
75
|
-
t.boolean "lunch"
|
76
|
-
|
77
|
-
|
71
|
+
...中略
|
78
|
-
|
79
|
-
t.boolean "dinner"
|
80
|
-
|
81
|
-
t.boolean "aniversary"
|
82
|
-
|
83
|
-
t.boolean "oneyear_ani"
|
84
|
-
|
85
|
-
t.boolean "onemonth_ani"
|
86
|
-
|
87
|
-
t.boolean "xmas"
|
88
|
-
|
89
|
-
t.boolean "valentine"
|
90
|
-
|
91
|
-
t.boolean "whiteday"
|
92
72
|
|
93
73
|
t.datetime "created_at", null: false
|
94
74
|
|
@@ -104,6 +84,10 @@
|
|
104
84
|
|
105
85
|
development.log
|
106
86
|
|
87
|
+
postリクエストでparameterが送られてテーブルに保存されるはずなのに
|
88
|
+
|
89
|
+
アソシーション先モデルにカラムが挿入されずどこか宇宙にデータが消えていく現象が起きています。
|
90
|
+
|
107
91
|
```log
|
108
92
|
|
109
93
|
Parameters: {
|
@@ -134,7 +118,7 @@
|
|
134
118
|
|
135
119
|
respond_to do |format|
|
136
120
|
|
137
|
-
if @post.save
|
121
|
+
if @post.save
|
138
122
|
|
139
123
|
format.html { redirect_to @post, notice: 'Post was successfully created.' }
|
140
124
|
|
@@ -196,72 +180,52 @@
|
|
196
180
|
|
197
181
|
<%= form_for(@post) do |f| %>
|
198
182
|
|
199
|
-
<% if @post.errors.any? %>
|
200
|
-
|
201
|
-
|
183
|
+
<div class="field">
|
202
|
-
|
203
|
-
|
184
|
+
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
<ul>
|
208
|
-
|
209
|
-
<% @post.errors.full_messages.each do |message| %>
|
210
|
-
|
211
|
-
|
185
|
+
<%= f.label :titile %><br>
|
212
|
-
|
186
|
+
|
213
|
-
|
187
|
+
<%= f.text_field :titile %>
|
214
|
-
|
188
|
+
|
215
|
-
|
189
|
+
</div>
|
190
|
+
|
191
|
+
...中略
|
192
|
+
|
193
|
+
<%= fields_for @post.hashtag do |h| %>
|
194
|
+
|
195
|
+
<div class="field">
|
196
|
+
|
197
|
+
<%= h.hidden_field :post_id, :value => @post.id %>
|
198
|
+
|
199
|
+
<%= h.label :couple %>
|
200
|
+
|
201
|
+
<%= h.check_box :couple %>
|
216
202
|
|
217
203
|
</div>
|
218
204
|
|
205
|
+
<div class="field">
|
206
|
+
|
207
|
+
<%= h.label :firstdate %>
|
208
|
+
|
209
|
+
<%= h.check_box :firstdate %>
|
210
|
+
|
211
|
+
</div>
|
212
|
+
|
213
|
+
...中略
|
214
|
+
|
219
215
|
<% end %>
|
220
216
|
|
217
|
+
|
218
|
+
|
221
|
-
<div class="
|
219
|
+
<div class="actions">
|
222
|
-
|
223
|
-
|
220
|
+
|
224
|
-
|
225
|
-
<%= f.
|
221
|
+
<%= f.submit %>
|
226
222
|
|
227
223
|
</div>
|
228
224
|
|
229
|
-
...中略
|
230
|
-
|
231
|
-
<%= fields_for @post.hashtag do |h| %>
|
232
|
-
|
233
|
-
<div class="field">
|
234
|
-
|
235
|
-
<%= h.label :couple %>
|
236
|
-
|
237
|
-
<%= h.check_box :couple, {class: "chk"}, "true", "false" %>
|
238
|
-
|
239
|
-
</div>
|
240
|
-
|
241
|
-
<div class="field">
|
242
|
-
|
243
|
-
<%= h.label :firstdate %>
|
244
|
-
|
245
|
-
<%= h.check_box :firstdate, {class: "chk"}, "true", "false" %>
|
246
|
-
|
247
|
-
</div>
|
248
|
-
|
249
|
-
...中略
|
250
|
-
|
251
|
-
<% end %>
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
<div class="actions">
|
256
|
-
|
257
|
-
<%= f.submit %>
|
258
|
-
|
259
|
-
</div>
|
260
|
-
|
261
225
|
<% end %>
|
262
226
|
|
263
227
|
|
264
228
|
|
265
229
|
```
|
266
230
|
|
267
|
-
|
231
|
+
parameterが宇宙に消えていきます・・・
|
4
table情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,102 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
前提
|
10
|
+
|
11
|
+
postsテーブル
|
12
|
+
|
13
|
+
hashtagsテーブル
|
14
|
+
|
15
|
+
postsとhashtagsは1対1の関係
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
postsテーブル
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
|
23
|
+
create_table "posts", force: :cascade do |t|
|
24
|
+
|
25
|
+
t.string "titile"
|
26
|
+
|
27
|
+
t.integer "user_id"
|
28
|
+
|
29
|
+
t.integer "restaurant_id"
|
30
|
+
|
31
|
+
t.text "content"
|
32
|
+
|
33
|
+
t.string "time_zone"
|
34
|
+
|
35
|
+
t.integer "amount"
|
36
|
+
|
37
|
+
t.integer "total_eval"
|
38
|
+
|
39
|
+
t.integer "quality_eval"
|
40
|
+
|
41
|
+
t.integer "service_eval"
|
42
|
+
|
43
|
+
t.integer "atomos_eval"
|
44
|
+
|
45
|
+
t.integer "drink_eval"
|
46
|
+
|
47
|
+
t.integer "partner_eval"
|
48
|
+
|
49
|
+
t.datetime "visit_date"
|
50
|
+
|
51
|
+
t.string "url"
|
52
|
+
|
53
|
+
t.datetime "created_at", null: false
|
54
|
+
|
55
|
+
t.datetime "updated_at", null: false
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
hashtagsテーブル
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
|
65
|
+
create_table "hashtags", force: :cascade do |t|
|
66
|
+
|
67
|
+
t.boolean "couple"
|
68
|
+
|
69
|
+
t.boolean "firstdate"
|
70
|
+
|
71
|
+
t.boolean "onesidelove"
|
72
|
+
|
73
|
+
t.boolean "confession"
|
74
|
+
|
75
|
+
t.boolean "lunch"
|
76
|
+
|
77
|
+
t.boolean "cafe"
|
78
|
+
|
79
|
+
t.boolean "dinner"
|
80
|
+
|
81
|
+
t.boolean "aniversary"
|
82
|
+
|
83
|
+
t.boolean "oneyear_ani"
|
84
|
+
|
85
|
+
t.boolean "onemonth_ani"
|
86
|
+
|
87
|
+
t.boolean "xmas"
|
88
|
+
|
89
|
+
t.boolean "valentine"
|
90
|
+
|
91
|
+
t.boolean "whiteday"
|
92
|
+
|
93
|
+
t.datetime "created_at", null: false
|
94
|
+
|
95
|
+
t.datetime "updated_at", null: false
|
96
|
+
|
97
|
+
t.integer "post_id"
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
|
104
|
+
|
9
105
|
development.log
|
10
106
|
|
11
107
|
```log
|
3
formの中身を編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -132,13 +132,13 @@
|
|
132
132
|
|
133
133
|
...中略
|
134
134
|
|
135
|
-
<%= fields_for
|
135
|
+
<%= fields_for @post.hashtag do |h| %>
|
136
136
|
|
137
137
|
<div class="field">
|
138
138
|
|
139
139
|
<%= h.label :couple %>
|
140
140
|
|
141
|
-
<%= h.check_box :couple, {}, true, false %>
|
141
|
+
<%= h.check_box :couple, {class: "chk"}, "true", "false" %>
|
142
142
|
|
143
143
|
</div>
|
144
144
|
|
@@ -146,99 +146,11 @@
|
|
146
146
|
|
147
147
|
<%= h.label :firstdate %>
|
148
148
|
|
149
|
-
<%= h.check_box :firstdate, {}, true, false %>
|
149
|
+
<%= h.check_box :firstdate, {class: "chk"}, "true", "false" %>
|
150
150
|
|
151
151
|
</div>
|
152
152
|
|
153
|
-
<div class="field">
|
154
|
-
|
155
|
-
<%= h.label :onesidelove %>
|
156
|
-
|
157
|
-
<%= h.check_box :onesidelove, {}, true, false %>
|
158
|
-
|
159
|
-
|
153
|
+
...中略
|
160
|
-
|
161
|
-
<div class="field">
|
162
|
-
|
163
|
-
<%= h.label :confession %>
|
164
|
-
|
165
|
-
<%= h.check_box :confession, {}, true, false %>
|
166
|
-
|
167
|
-
</div>
|
168
|
-
|
169
|
-
<div class="field">
|
170
|
-
|
171
|
-
<%= h.label :lunch %>
|
172
|
-
|
173
|
-
<%= h.check_box :lunch, {}, true, false %>
|
174
|
-
|
175
|
-
</div>
|
176
|
-
|
177
|
-
<div class="field">
|
178
|
-
|
179
|
-
<%= h.label :cafe %>
|
180
|
-
|
181
|
-
<%= h.check_box :cafe, {}, true, false %>
|
182
|
-
|
183
|
-
</div>
|
184
|
-
|
185
|
-
<div class="field">
|
186
|
-
|
187
|
-
<%= h.label :dinner %>
|
188
|
-
|
189
|
-
<%= h.check_box :dinner, {}, true, false %>
|
190
|
-
|
191
|
-
</div>
|
192
|
-
|
193
|
-
<div class="field">
|
194
|
-
|
195
|
-
<%= h.label :aniversary %>
|
196
|
-
|
197
|
-
<%= h.check_box :aniversary, {}, true, false %>
|
198
|
-
|
199
|
-
</div>
|
200
|
-
|
201
|
-
<div class="field">
|
202
|
-
|
203
|
-
<%= h.label :oneyear_ani %>
|
204
|
-
|
205
|
-
<%= h.check_box :oneyear_ani, {}, true, false %>
|
206
|
-
|
207
|
-
</div>
|
208
|
-
|
209
|
-
<div class="field">
|
210
|
-
|
211
|
-
<%= h.label :onemonth_ani %>
|
212
|
-
|
213
|
-
<%= h.check_box :onemonth_ani, {}, true, false %>
|
214
|
-
|
215
|
-
</div>
|
216
|
-
|
217
|
-
<div class="field">
|
218
|
-
|
219
|
-
<%= h.label :xmas %>
|
220
|
-
|
221
|
-
<%= h.check_box :xmas, {}, true, false %>
|
222
|
-
|
223
|
-
</div>
|
224
|
-
|
225
|
-
<div class="field">
|
226
|
-
|
227
|
-
<%= h.label :valentine %>
|
228
|
-
|
229
|
-
<%= h.check_box :valentine, {}, true, false %>
|
230
|
-
|
231
|
-
</div>
|
232
|
-
|
233
|
-
<div class="field">
|
234
|
-
|
235
|
-
<%= h.label :whiteday %>
|
236
|
-
|
237
|
-
<%= h.check_box :whiteday, {}, true, false %>
|
238
|
-
|
239
|
-
</div>
|
240
|
-
|
241
|
-
|
242
154
|
|
243
155
|
<% end %>
|
244
156
|
|
2
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby on rails
|
1
|
+
【ruby on rails】一画面で自モデルとhas_one先のmodelにデータが保存する方法
|
test
CHANGED
File without changes
|
1
変更したのに消えた最悪。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,26 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
development.log
|
10
|
+
|
11
|
+
```log
|
12
|
+
|
13
|
+
Parameters: {
|
14
|
+
|
15
|
+
"post"=>{"titile"=>"", "user_id"=>"", "restaurant_id"=>"4", "content"=>"", "time_zone"=>"昼", "amount"=>"500", "total_eval"=>"1", "quality_eval"=>"1", "service_eval"=>"1", "atomos_eval"=>"1", "drink_eval"=>"1", "partner_eval"=>"1", "visit_date"=>"", "url"=>""},
|
16
|
+
|
17
|
+
"hashtag"=>{"post_id"=>"", "couple"=>"false", "firstdate"=>"false", "onesidelove"=>"false", "lunch"=>"true", "cafe"=>"true", "dinner"=>"true"},
|
18
|
+
|
19
|
+
"commit"=>"Create Post"}
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
1mINSERT INTO "hashtags" ("post_id", "created_at", "updated_at") VALUES (?, ?, ?)
|
24
|
+
|
25
|
+
[0m [["post_id", 35], ["created_at", "2016-01-09 03:56:13.588032"], ["updated_at", "2016-01-09 03:56:13.588032"]]
|
26
|
+
|
27
|
+
```
|
28
|
+
|
9
29
|
postscontroller.rb
|
10
30
|
|
11
31
|
```ruby
|
@@ -14,7 +34,7 @@
|
|
14
34
|
|
15
35
|
@post = Post.new(post_params)
|
16
36
|
|
17
|
-
@post.
|
37
|
+
@post.create_hashtag
|
18
38
|
|
19
39
|
respond_to do |format|
|
20
40
|
|