質問編集履歴

4

誤字の修正

2021/05/29 13:34

投稿

itiapotami
itiapotami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -320,7 +320,7 @@
320
320
 
321
321
 
322
322
 
323
- エラー文からNameerrortoと推測してclass名を確認するもミスが見つからず、collection_check_boxをコメントアウトするとcheck_box以外は正常に表示されデータベースへの保存も可能でした。
323
+ エラー文からName errorと推測してclass名を確認するもミスが見つからず、collection_check_boxをコメントアウトするとcheck_box以外は正常に表示されデータベースへの保存も可能でした。
324
324
 
325
325
  何かお気づきの点があればアドバイス頂けると幸いです
326
326
 

3

誤字の修正

2021/05/29 13:34

投稿

itiapotami
itiapotami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -320,7 +320,7 @@
320
320
 
321
321
 
322
322
 
323
- エラー文からNameerrortoと推測してclass名を確認するもミスが見つからず、collection_check_boxをコメントトすると正常に表示されデータベースへの保存も可能でした。
323
+ エラー文からNameerrortoと推測してclass名を確認するもミスが見つからず、collection_check_boxをコメントアウトするとcheck_box以外は正常に表示されデータベースへの保存も可能でした。
324
324
 
325
325
  何かお気づきの点があればアドバイス頂けると幸いです
326
326
 

2

binding.pryを削除

2021/05/28 03:52

投稿

itiapotami
itiapotami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -132,8 +132,6 @@
132
132
 
133
133
  def new
134
134
 
135
- binding.pry
136
-
137
135
  @hotel = Hotel.find(params[:hotel_id])
138
136
 
139
137
  @room = Room.new

1

エラー内容の詳細の追加と該当箇所の変更

2021/05/25 15:58

投稿

itiapotami
itiapotami

スコア1

test CHANGED
File without changes
test CHANGED
@@ -10,21 +10,111 @@
10
10
 
11
11
  ### 発生している問題・エラーメッセージ
12
12
 
13
- フォームに値入力てリクエスト送信するとエラーが発生します
14
-
15
- 具体的にはデタベースに保存ができません
16
-
17
- ```
18
-
19
- エラーメッセージ
20
-
21
- ```
22
-
23
- Parameters: {"authenticity_token"=>"UypT907GBkwQxS9iDpcyPKnzIywoIOzQkYvHhLdNz5z7nbZxFVqYM/wm1H2g8Dsh6d69Xd3omaUqENFmgvHkPA==", "room"=>{"room_name"=>"テストの部屋", "capacity"=>"4", "price"=>"3000", "image"=>#<ActionDispatch::Http::UploadedFile:0x00007fb8a71e5228 @tempfile=#<Tempfile:/var/folders/9b/dcq93xs54d96fhjkvq8pncb40000gn/T/RackMultipart20210524-10316-176oe90.png>, @original_filename="test.hotel.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"room[image]\"; filename=\"test.hotel.png\"\r\nContent-Type: image/png\r\n">}, "Room"=>{"facility_ids"=>["", "1", "2", "3"]}, "commit"=>"登録", "hotel_id"=>"1"}
24
-
25
- No template found for RoomsController#create, rendering head :no_content
26
-
27
- Completed 204 No Content in 123ms (ActiveRecord: 37.2ms | Allocations: 15179)
13
+ collection_check_boxes実装ようと記述しview表示するとエラーが発生します
14
+
15
+ ![イメジ説明](065a277b8f43754fb45ba06f7d2b93bd.png)
16
+
17
+
18
+
19
+ view/rooms/new.html.erb
20
+
21
+ ```ruby
22
+
23
+ <div class='hotel-post-contents'>
24
+
25
+ <div class='hotel-left-contents'>
26
+
27
+ <div class='hotel-post-main'>
28
+
29
+ <h2 class='hotel-post-title'>宿泊施設の登録を始めましょう</h2>
30
+
31
+ <%= form_with model:[@hotel, @room], local: true do |f| %>
32
+
33
+ <%# ホテル名と説明%>
34
+
35
+ <div class="new-hotel">
36
+
37
+ <div class="weight-bold-text">
38
+
39
+ 部屋名
40
+
41
+ </div>
42
+
43
+ <%= f.text_field :room_name, class:"hotel-name-text", id:"room-name", placeholder:"部屋の名前", maxlength:"40" %>
44
+
45
+ <div class="hotel-information">
46
+
47
+ <div class="weight-bold-text">
48
+
49
+ 定員人数
50
+
51
+ </div>
52
+
53
+ <%= f.text_field :capacity, class:"hotel-text", id:"capacity", placeholder:"例)6", maxlength:"2" %>
54
+
55
+ <div class="weight-bold-text">
56
+
57
+ 料金
58
+
59
+ </div>
60
+
61
+ <%= f.text_field :price, class:"hotel-text", id:"price", placeholder:"例)3000" %>
62
+
63
+ <div class="weight-bold-text">
64
+
65
+ 部屋トップ画像
66
+
67
+ </div>
68
+
69
+ <%= f.file_field :image, id:"room-image" %>
70
+
71
+ <div class="weight-bold-text">
72
+
73
+ 設備
74
+
75
+ </div>
76
+
77
+ <%# 設備は今後実装%>
78
+
79
+ <div class='facility-contents'>
80
+
81
+
82
+
83
+ <%= f.collection_check_boxes :facility_ids, Facility.all, :id, :name, include_hidden: false do |b| %>
84
+
85
+ <% b.label {b.check_box + b.text} %>
86
+
87
+ <% end %>
88
+
89
+
90
+
91
+
92
+
93
+ </div>
94
+
95
+
96
+
97
+ <div class='registration-button'>
98
+
99
+ <%= f.submit "登録" ,class:"registration-blue-button" %>
100
+
101
+ </div>
102
+
103
+ </div>
104
+
105
+ <% end %>
106
+
107
+ </div>
108
+
109
+ </div>
110
+
111
+ <div class='hotel-right-contents'>
112
+
113
+ </div>
114
+
115
+ </div>
116
+
117
+ ```
28
118
 
29
119
 
30
120
 
@@ -34,9 +124,17 @@
34
124
 
35
125
  ```ruby
36
126
 
37
-
127
+ class RoomsController < ApplicationController
38
-
128
+
129
+
130
+
131
+
132
+
39
- def new
133
+ def new
134
+
135
+ binding.pry
136
+
137
+ @hotel = Hotel.find(params[:hotel_id])
40
138
 
41
139
  @room = Room.new
42
140
 
@@ -46,11 +144,19 @@
46
144
 
47
145
  def create
48
146
 
147
+ @hotel = Hotel.find(params[:hotel_id])
148
+
49
149
  @room = Room.new(room_params)
50
150
 
151
+
152
+
51
153
  if @room.save
52
154
 
53
- redirect_to root_path
155
+ redirect_to hotel_path
156
+
157
+ else
158
+
159
+ render :new
54
160
 
55
161
  end
56
162
 
@@ -62,7 +168,7 @@
62
168
 
63
169
  def room_params
64
170
 
65
- params.require(:room).permit(:room_name, :capacity, :price, :hotel_id, :image, facility_id:[])
171
+ params.require(:room).permit(:room_name, :capacity, :price, :image, {facility_ids: []}).merge(owner_id: current_owner.id, hotel_id: params[:hotel_id])
66
172
 
67
173
  end
68
174
 
@@ -78,87 +184,13 @@
78
184
 
79
185
  resources :hotels, only: [:index, :new, :create, :show] do
80
186
 
81
- resources :rooms, only: [:index, :new, :create]
187
+ resources :rooms, only: [:new, :create]
82
-
188
+
83
- end
189
+ end
84
-
190
+
85
- ```
191
+ ```
86
-
87
- new.html.erb
192
+
88
-
89
- ```ruby
193
+
90
-
91
- <%= form_with model:[@hotel, @room], url: hotel_rooms_path, local: true do |f| %>
92
-
93
- <%# ホテル名と説明%>
94
-
95
- <div class="new-hotel">
96
-
97
- <div class="weight-bold-text">
98
-
99
- 部屋名
100
-
101
- </div>
102
-
103
- <%= f.text_field :room_name, class:"hotel-name-text", id:"room-name", placeholder:"部屋の名前", maxlength:"40" %>
104
-
105
- <div class="hotel-information">
106
-
107
- <div class="weight-bold-text">
108
-
109
- 定員人数
110
-
111
- </div>
112
-
113
- <%= f.text_field :capacity, class:"hotel-text", id:"capacity", placeholder:"例)6", maxlength:"2" %>
114
-
115
- <div class="weight-bold-text">
116
-
117
- 料金
118
-
119
- </div>
120
-
121
- <%= f.text_field :price, class:"hotel-text", id:"price", placeholder:"例)3000" %>
122
-
123
- <div class="weight-bold-text">
124
-
125
- 部屋トップ画像
126
-
127
- </div>
128
-
129
- <%= f.file_field :image, id:"room-image" %>
130
-
131
- <div class="weight-bold-text">
132
-
133
- 設備
134
-
135
- </div>
136
-
137
-
138
-
139
- <div class='facility-contents'>
140
-
141
- <%= collection_check_boxes(:Room, :facility_ids, Facility.all, :id, :name) do |b| %>
142
-
143
- <%= b.label { b.check_box + b.text } %>
144
-
145
- <% end %>
146
-
147
- </div>
148
-
149
-
150
-
151
- <div class='registration-button'>
152
-
153
- <%= f.submit "登録" ,class:"registration-blue-button" %>
154
-
155
- </div>
156
-
157
- </div>
158
-
159
- <% end %>
160
-
161
- ```
162
194
 
163
195
  room.rb
164
196
 
@@ -192,8 +224,6 @@
192
224
 
193
225
  has_many :rooms, through: :room_haves
194
226
 
195
- has_many :hotels
196
-
197
227
  end
198
228
 
199
229
  ```
@@ -212,7 +242,7 @@
212
242
 
213
243
  ```
214
244
 
215
- room migration
245
+ rooms migration
216
246
 
217
247
  ```ruby
218
248
 
@@ -228,6 +258,8 @@
228
258
 
229
259
  t.string :price, null: false
230
260
 
261
+ t.references :owner, foreign_key: true
262
+
231
263
  t.references :hotel, foreign_key: true
232
264
 
233
265
  t.timestamps
@@ -290,12 +322,42 @@
290
322
 
291
323
 
292
324
 
293
- エラー文ではcreateアクションに対するテンプレートないと言われていたのでredirect_toで遷移先指定しましたが改善きませんでした
325
+ エラー文からNameerrortoと推測してclass名を確認するもミス見つからず、collection_check_boxコメントストすると正常に表示されデータベースへの保存も可能でした
326
+
327
+ 何かお気づきの点があればアドバイス頂けると幸いです
294
328
 
295
329
 
296
330
 
297
331
  ### 補足情報(FW/ツールのバージョンなど)
298
332
 
299
-
333
+ コンソールのエラー情報
334
+
300
-
335
+ ```ruby
336
+
337
+ ActionView::Template::Error (uninitialized constant Room::RoomHafe):
338
+
339
+ 30: <div class='facility-contents'>
340
+
341
+ 31:
342
+
343
+ 32: <%= f.collection_check_boxes :facility_ids, Facility.all, :id, :name, include_hidden: false do |b| %>
344
+
345
+ 33: <% b.label {b.check_box + b.text} %>
346
+
301
- ここにより詳細な情報を記載してください。
347
+ 34: <% end %>
348
+
349
+ 35:
350
+
351
+ 36:
352
+
353
+
354
+
355
+ app/views/rooms/new.html.erb:33
356
+
357
+ app/views/rooms/new.html.erb:33
358
+
359
+ app/views/rooms/new.html.erb:32
360
+
361
+ app/views/rooms/new.html.erb:6
362
+
363
+ ```