質問編集履歴
2
rooms_pathをroom_pathに変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,6 +46,66 @@
|
|
46
46
|
|
47
47
|
def show
|
48
48
|
|
49
|
+
@room = Room.find(params[:id])
|
50
|
+
|
51
|
+
@messages = @room.messages.includes(:user).order(:id).last(100)
|
52
|
+
|
53
|
+
@message = current_user.messages.build
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
### rooms_controller.rb
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
|
67
|
+
class RoomsController < ApplicationController
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
def index
|
72
|
+
|
73
|
+
@rooms = Room.all.order(:id)
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
def new
|
80
|
+
|
81
|
+
@room = Room.new
|
82
|
+
|
83
|
+
@room.users << current_user
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def create
|
90
|
+
|
91
|
+
@room =Room.new(room_params)
|
92
|
+
|
93
|
+
if @room.save
|
94
|
+
|
95
|
+
redirect_to root_path
|
96
|
+
|
97
|
+
else
|
98
|
+
|
99
|
+
render :new
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
def show
|
108
|
+
|
49
109
|
@room = Room.find(params[:id]) #この行がエラーメッセージの対象となっています。
|
50
110
|
|
51
111
|
@messages = @room.messages.includes(:user).order(:id).last(100)
|
@@ -54,11 +114,35 @@
|
|
54
114
|
|
55
115
|
end
|
56
116
|
|
117
|
+
|
118
|
+
|
119
|
+
def show_additionally
|
120
|
+
|
121
|
+
last_id = params[:oldest_message_id].to_i - 1
|
122
|
+
|
123
|
+
@messages = Message.includes(:user).order(:id).where(id: 1..last_id).last(50)
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
def room_params
|
134
|
+
|
135
|
+
params.require(:room).permit(:name).merge(user_ids: current_user.id)
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
57
|
-
```
|
141
|
+
```
|
58
|
-
|
59
|
-
|
60
|
-
|
142
|
+
|
143
|
+
|
144
|
+
|
61
|
-
###
|
145
|
+
### index.html.erb
|
62
146
|
|
63
147
|
|
64
148
|
|
@@ -66,75 +150,89 @@
|
|
66
150
|
|
67
151
|
class RoomsController < ApplicationController
|
68
152
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@rooms
|
74
|
-
|
75
|
-
en
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
153
|
+
<div class="room_index_main">
|
154
|
+
|
155
|
+
<ul class="family_lists">
|
156
|
+
|
157
|
+
<% @rooms.each do |room| %>
|
158
|
+
|
159
|
+
<li class="family_list"><%= link_to "#{room.name}", room_path(room.id), class:"family_button" %></li>
|
160
|
+
|
161
|
+
<% end %>
|
162
|
+
|
163
|
+
</ul>
|
164
|
+
|
165
|
+
</div>
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
### new.html.erb
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
|
177
|
+
<div id="message-container" data-room_id = "<%= @room.id %>">
|
178
|
+
|
179
|
+
<%= render @messages %>
|
180
|
+
|
181
|
+
</div>
|
182
|
+
|
183
|
+
<%= render 'footer' %>
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
### routes.rb
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
|
195
|
+
Rails.application.routes.draw do
|
196
|
+
|
197
|
+
mount ActionCable.server => "/cable"
|
198
|
+
|
199
|
+
resources :rooms, only: [:index, :new, :show, :create, :update] do
|
200
|
+
|
201
|
+
resources :messages, only: [:create]
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
root to: "users#show"
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
devise_for :users, controllers: {
|
212
|
+
|
213
|
+
registrations: "users/registrations",
|
214
|
+
|
215
|
+
sessions: "users/sessions"
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
resources :users, only: [:show]
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
get "/show_additionally", to: "rooms#show_additionally"
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
devise_scope :user do
|
230
|
+
|
231
|
+
get "sign_in", to: "users/sessions#new"
|
232
|
+
|
233
|
+
get "sign_out", to: "users/sessions#destroy"
|
234
|
+
|
235
|
+
end
|
138
236
|
|
139
237
|
end
|
140
238
|
|
@@ -142,104 +240,6 @@
|
|
142
240
|
|
143
241
|
|
144
242
|
|
145
|
-
### index.html.erb
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
|
151
|
-
class RoomsController < ApplicationController
|
152
|
-
|
153
|
-
<div class="room_index_main">
|
154
|
-
|
155
|
-
<ul class="family_lists">
|
156
|
-
|
157
|
-
<% @rooms.each do |room| %>
|
158
|
-
|
159
|
-
<li class="family_list"><%= link_to "#{room.name}", rooms_path(room.id), class:"family_button" %></li>
|
160
|
-
|
161
|
-
<% end %>
|
162
|
-
|
163
|
-
</ul>
|
164
|
-
|
165
|
-
</div>
|
166
|
-
|
167
|
-
```
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
### new.html.erb
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
```ruby
|
176
|
-
|
177
|
-
<div id="message-container" data-room_id = "<%= @room.id %>">
|
178
|
-
|
179
|
-
<%= render @messages %>
|
180
|
-
|
181
|
-
</div>
|
182
|
-
|
183
|
-
<%= render 'footer' %>
|
184
|
-
|
185
|
-
```
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
### routes.rb
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
|
195
|
-
Rails.application.routes.draw do
|
196
|
-
|
197
|
-
mount ActionCable.server => "/cable"
|
198
|
-
|
199
|
-
resources :rooms, only: [:index, :new, :show, :create, :update] do
|
200
|
-
|
201
|
-
resources :messages, only: [:create]
|
202
|
-
|
203
|
-
end
|
204
|
-
|
205
|
-
root to: "users#show"
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
devise_for :users, controllers: {
|
212
|
-
|
213
|
-
registrations: "users/registrations",
|
214
|
-
|
215
|
-
sessions: "users/sessions"
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
resources :users, only: [:show]
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
get "/show_additionally", to: "rooms#show_additionally"
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
devise_scope :user do
|
230
|
-
|
231
|
-
get "sign_in", to: "users/sessions#new"
|
232
|
-
|
233
|
-
get "sign_out", to: "users/sessions#destroy"
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
```
|
240
|
-
|
241
|
-
|
242
|
-
|
243
243
|
### 試したこと
|
244
244
|
|
245
245
|
|
1
エラーの詳細を追加いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,13 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
ルームコントローラーのindexアクションとshowアクションの機能を実装しておりました。
|
22
|
+
|
23
|
+
その過程で、incexのビューページにshowアクションのページに遷移するためのリンクを記述しています。
|
24
|
+
|
21
|
-
|
25
|
+
indexの記述に問題はなさそうなのですが、rooms_controllerのshowアクションのidの中身がindexとなってますという、エラーメッセージが発生しました。
|
22
|
-
|
26
|
+
|
23
|
-
index.html.erbのビューページにアクセスしようとすると、以下のようなエラ
|
27
|
+
index.html.erbのビューページにアクセスしようとすると、以下のようなエラーメッセージがでます。
|
24
28
|
|
25
29
|
どうしてこのようなことが起きるのかについて教えていただきたいです。
|
26
30
|
|