質問編集履歴

1

写真ではなくコードで記載致しました。ご不便おかけしてすみませんでした。

2020/07/30 08:19

投稿

kuma0808
kuma0808

スコア0

test CHANGED
File without changes
test CHANGED
@@ -18,23 +18,289 @@
18
18
 
19
19
  routes.rb
20
20
 
21
+ ```
22
+
23
+ Rails.application.routes.draw do
24
+
25
+ devise_for :users
26
+
27
+ # root 'messages#index'
28
+
29
+ root 'groups#index'
30
+
31
+ resources :users, only: [:edit, :update]
32
+
33
+ resources :groups, only: [:index, :new, :create, :edit, :update]
34
+
35
+ resources :members, only: [:index,:edit] do
36
+
21
- ![イメージ説明](60aa60c964c1e66a66d92b6d8ef336e7.png)
37
+ resources :messages, only: [:index, :create]
38
+
39
+ end
40
+
41
+
42
+
43
+ # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
44
+
45
+ end
46
+
47
+ ```
22
48
 
23
49
  messages_controller.rb
24
50
 
25
- ![イメージ説明](3af3b185ef8481367d33f47b37883138.png)
26
-
27
- message.rb
28
-
29
- ![イメージ説明](c618a687e0e530461bee5ddfc1d4d5f6.png)
30
-
31
- create_messages.rb
32
-
33
- ![イメージ説明](a0425b4c5791769e8f85ead9d9236a39.png)
34
-
35
-
36
-
37
- ![イメージ説明](2a1ce75ad6dd62ad3ec25162c56f7e96.png)
51
+ ```ここに言語を入力
52
+
53
+ class MessagesController < ApplicationController
54
+
55
+ before_action :set_group
56
+
57
+
58
+
59
+ def index
60
+
61
+ @message = Message.new
62
+
63
+ @messages = @group.messages.includes(:user)
64
+
65
+ end
66
+
67
+
68
+
69
+ def create
70
+
71
+ @message = @group.messages.new(message_params)
72
+
73
+ if @message.save
74
+
75
+ redirect_to group_messages_path(@group), notice: 'メッセージが送信されました'
76
+
77
+ else
78
+
79
+ @messages = @group.messages.includes(:user)
80
+
81
+ flash.now[:alert] = 'メッセージを入力してください。'
82
+
83
+ render :index
84
+
85
+ end
86
+
87
+ end
88
+
89
+
90
+
91
+ private
92
+
93
+
94
+
95
+ def message_params
96
+
97
+ params.require(:message).permit(:ondo, :symptom, :Textarea).merge(user_id: current_user.id)
98
+
99
+ end
100
+
101
+
102
+
103
+ def set_group
104
+
105
+ @group = Group.find(params[:group_id])
106
+
107
+ end
108
+
109
+ end
110
+
111
+ ```
112
+
113
+ messages.rb
114
+
115
+ ```ここに言語を入力
116
+
117
+ class Message < ApplicationRecord
118
+
119
+ belongs_to :group
120
+
121
+ belongs_to :user
122
+
123
+ validates :ondo, presence: true
124
+
125
+ validates :Textarea, presence: true
126
+
127
+ validates :symptom, presence: true, inclusion: { in: 1..2 }
128
+
129
+ end
130
+
131
+
132
+
133
+ ```
134
+
135
+ 20200730021825_create_messages.rb
136
+
137
+ ```ここに言語を入力
138
+
139
+ class CreateMessages < ActiveRecord::Migration[6.0]
140
+
141
+ def change
142
+
143
+ create_table :messages do |t|
144
+
145
+ t.integer :ondo
146
+
147
+ t.integer :symptom
148
+
149
+ t.string :Textarea
150
+
151
+ t.references :group, foreign_key: true
152
+
153
+ t.references :user, foreign_key: true
154
+
155
+ t.timestamps
156
+
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+
164
+
165
+ ```
166
+
167
+
168
+
169
+ message送信のview
170
+
171
+ ```ここに言語を入力
172
+
173
+ .side
174
+
175
+ .side__Header
176
+
177
+ .side__Header--Box
178
+
179
+ %ul.list
180
+
181
+ %li.list__list-icon
182
+
183
+ =link_to edit_user_path(current_user) do
184
+
185
+ = icon('fas', 'user-edit')
186
+
187
+ %span.name
188
+
189
+ = icon('fas', 'user-circle')
190
+
191
+ =current_user.name
192
+
193
+
194
+
195
+ .side__Contents
196
+
197
+ -# - current_user.groups.each do |group|
198
+
199
+ -# .Group
200
+
201
+ -# = link_to '#' do
202
+
203
+ -# .Group__name
204
+
205
+ -# = group.name
206
+
207
+ .side__Contents--Box
208
+
209
+ .side__Footer
210
+
211
+ = form_with model: [@group, @message], html: {class: "Form"}, local: true do |f|
212
+
213
+ -# .Form__contents
214
+
215
+ -# = f.text_field :content, class: 'Form__inputContent', placeholder: 'type a message'
216
+
217
+ -# = f.submit 'Send', class: 'Form__submit'
218
+
219
+ -# %form.Form
220
+
221
+ -# .Form__Heat
222
+
223
+ -# %span.heat
224
+
225
+ -# 体温
226
+
227
+ -# %select.Field{:name => "ondo",required:""}
228
+
229
+ -# %option{:value => ""} - - - - - -
230
+
231
+ -# %option{:value => "1",} 36.4以下
232
+
233
+ -# %option{:value => "2",} 36.5
234
+
235
+ -# %option{:value => "3"} 36.6
236
+
237
+ -# %option{:value => "4"} 36.7
238
+
239
+ -# %option{:value => "5"} 36.8
240
+
241
+ -# %option{:value => "6"} 36.9
242
+
243
+ -# %option{:value => "7"} 37.0
244
+
245
+ -# %option{:value => "8"} 37.1
246
+
247
+ -# %option{:value => "9"} 37.2
248
+
249
+ -# %option{:value => "10"} 37.3
250
+
251
+ -# %option{:value => "11"} 37.4
252
+
253
+ -# %option{:value => "12"} 37.5
254
+
255
+ -# %option{:value => "13"} 37.6
256
+
257
+ -# %option{:value => "14"} 37.7
258
+
259
+ -# %option{:value => "15"} 37.8
260
+
261
+ -# %option{:value => "16"} 37.9
262
+
263
+ -# %option{:value => "17"} 38.0
264
+
265
+ -# %option{:value => "18"} 38.1
266
+
267
+ -# %option{:value => "19"} 38.2
268
+
269
+ -# %option{:value => "20"} 38.3
270
+
271
+ -# %option{:value => "21"} 38.4
272
+
273
+ -# %option{:value => "22"} 38.5
274
+
275
+ -# %option{:value => "23"} 38.6以上
276
+
277
+ -# .Form__Symptom
278
+
279
+ -# %span.symptom
280
+
281
+ -# 症状
282
+
283
+ -# .Form__Symptom--Box
284
+
285
+ -# %input.Form__radio--button{type: "radio", name:"symptom", value: "1", required: ""} 有
286
+
287
+ -# %input.Form__radio--button{type: "radio",name:"symptom", value: "2"} 無
288
+
289
+ -# %span 入力必須
290
+
291
+ -# .Form__Textarea
292
+
293
+ -# %span.textarea
294
+
295
+ -# 症状詳細
296
+
297
+ -# %textarea.Form__textContent{type: "textarea"}
298
+
299
+ -# %button.Form__submit{type: "submit"}
300
+
301
+ -# 送信
302
+
303
+ ```
38
304
 
39
305
 
40
306