質問編集履歴
4
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2つのモデル間の
|
1
|
+
2つのモデル間のリレーションがはれない
|
test
CHANGED
File without changes
|
3
説明文修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
以下のようなモデル間(主:TargetServer, 副:Disk)で
|
2
2
|
|
3
|
-
リレーションを貼ってひとつのモデル
|
3
|
+
リレーションを貼ってひとつのフォームで複数のモデルをDBへ登録できるようにしようとしているのですが、TargetServerをAddしようとすると
|
4
4
|
|
5
5
|
|
6
6
|
|
2
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
7
11
|
undefined method `disk' for #<Targetserver:0x00007f7c25709358>
|
8
12
|
|
9
13
|
|
@@ -12,6 +16,10 @@
|
|
12
16
|
|
13
17
|
|
14
18
|
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
15
23
|
いろいろと調べたのですがうまく解決できなかったため
|
16
24
|
|
17
25
|
どなたか対応法をご教授いただければ幸いです。
|
@@ -207,3 +215,87 @@
|
|
207
215
|
end
|
208
216
|
|
209
217
|
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
(TargetServerをAddする際に呼び出す_form)
|
222
|
+
|
223
|
+
```
|
224
|
+
|
225
|
+
<%= form_with(model: targetserver, local: true) do |form| %>
|
226
|
+
|
227
|
+
<% if targetserver.errors.any? %>
|
228
|
+
|
229
|
+
<div id="error_explanation">
|
230
|
+
|
231
|
+
<h2><%= pluralize(targetserver.errors.count, "error") %> prohibited this targetserver from being saved:</h2>
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
<ul>
|
236
|
+
|
237
|
+
<% targetserver.errors.full_messages.each do |message| %>
|
238
|
+
|
239
|
+
<li><%= message %></li>
|
240
|
+
|
241
|
+
<% end %>
|
242
|
+
|
243
|
+
</ul>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<% end %>
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
<div class="field">
|
252
|
+
|
253
|
+
<%= form.label :hostname %>
|
254
|
+
|
255
|
+
<%= form.text_field :hostname, id: :targetserver_hostname %>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
<div class="field">
|
262
|
+
|
263
|
+
<%= form.label :cpumemory, "CPU & Memory" %>
|
264
|
+
|
265
|
+
<%= form.text_field :cpumemory, id: :targetserver_cpumemory %>
|
266
|
+
|
267
|
+
</div>
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
<div class="field">
|
272
|
+
|
273
|
+
<%= form.label :os, "OS" %>
|
274
|
+
|
275
|
+
<%= form.text_field :os, id: :targetserver_os %>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
<%= @targetserver.disk.each do |disk| %>
|
282
|
+
|
283
|
+
<%= hidden_field_tag :partitionname, id: :disk_partitionname, :value => "/" %>
|
284
|
+
|
285
|
+
<%= disk.label :disk_size %>
|
286
|
+
|
287
|
+
<%= disk.text_field :size, id: :disk_size %>
|
288
|
+
|
289
|
+
<% end %>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
<div class="actions">
|
294
|
+
|
295
|
+
<%= form.submit %>
|
296
|
+
|
297
|
+
</div>
|
298
|
+
|
299
|
+
<% end %>
|
300
|
+
|
301
|
+
```
|
1
エラーメッセージ更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
以下のようなモデル間(主:TargetServer, 副:Disk)で
|
2
2
|
|
3
|
-
リレーションを貼ってひとつのモデルでDBへ登録できるようにしようとしているのですが、
|
3
|
+
リレーションを貼ってひとつのモデルでDBへ登録できるようにしようとしているのですが、TargetServerをAddしようとすると
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
|
6
|
+
|
11
|
-
|
7
|
+
undefined method `disk' for #<Targetserver:0x00007f7c25709358>
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
と出てしまいます。。
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
class Targetserver < ApplicationRecord
|
30
30
|
|
31
|
-
has_many :disks
|
31
|
+
has_many :disks
|
32
32
|
|
33
33
|
accepts_nested_attributes_for :disks
|
34
34
|
|