質問編集履歴
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
|
91
91
|
# redirect_to family_records(@family), notice: '体温が送信されました'
|
92
92
|
|
93
|
-
flash[:notice] = '体
|
93
|
+
flash[:notice] = '体温を投稿しました。'
|
94
94
|
|
95
95
|
else
|
96
96
|
|
1
誤字、途中で投稿してしまったため。
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,85 @@
|
|
60
60
|
|
61
61
|
```Ruby
|
62
62
|
|
63
|
+
class RecordsController < ApplicationController
|
63
64
|
|
65
|
+
before_action :set_family
|
66
|
+
|
67
|
+
before_action :currect_user, only: [:destroy]
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def index
|
74
|
+
|
75
|
+
@record = Record.new
|
76
|
+
|
77
|
+
@records = @family.records.includes(:user)
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
def create
|
84
|
+
|
85
|
+
@record = current_user.records.build(record_params)
|
86
|
+
|
87
|
+
if @record.save
|
88
|
+
|
89
|
+
# @record = @family.records.new(record_params)
|
90
|
+
|
91
|
+
# redirect_to family_records(@family), notice: '体温が送信されました'
|
92
|
+
|
93
|
+
flash[:notice] = '体重を投稿しました。'
|
94
|
+
|
95
|
+
else
|
96
|
+
|
97
|
+
@records = @family.records.includes(:user)
|
98
|
+
|
99
|
+
flash[:alert] = '体温の投稿に失敗しました。'
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
redirect_to root_path
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def record_params
|
112
|
+
|
113
|
+
params.require(:record).permit(:value, :date)
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def set_family
|
120
|
+
|
121
|
+
@family = Family.find(params[:family_id])
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def currect_user
|
128
|
+
|
129
|
+
@record = current_user.records.find_by(id: params[:id])
|
130
|
+
|
131
|
+
unless @record
|
132
|
+
|
133
|
+
redirect_to root_path
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
```
|
64
142
|
|
65
143
|
|
66
144
|
|
@@ -68,7 +146,7 @@
|
|
68
146
|
|
69
147
|
|
70
148
|
|
71
|
-
|
149
|
+
体温のvalueがintegerだったのでrealに変更しました。
|
72
150
|
|
73
151
|
|
74
152
|
|
@@ -76,4 +154,42 @@
|
|
76
154
|
|
77
155
|
|
78
156
|
|
157
|
+
・Rails 5.0.7.2
|
158
|
+
|
159
|
+
・ruby 2.5.1p57
|
160
|
+
|
161
|
+
・postgreSQL
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
データーベース中身です。
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
Column | Type | Collation | Nullable | Default
|
172
|
+
|
173
|
+
------------+-----------------------------+-----------+----------+-------------------------------------
|
174
|
+
|
175
|
+
id | integer | | not null | nextval('records_id_seq'::regclass)
|
176
|
+
|
177
|
+
value | real | | |
|
178
|
+
|
179
|
+
user_id | integer | | |
|
180
|
+
|
181
|
+
family_id | integer | | |
|
182
|
+
|
183
|
+
created_at | timestamp without time zone | | not null |
|
184
|
+
|
185
|
+
updated_at | timestamp without time zone | | not null |
|
186
|
+
|
187
|
+
date | timestamp without time zone | | |
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
|
192
|
+
|
79
|
-
|
193
|
+
他に必要なコードがあればお申し付けください。
|
194
|
+
|
195
|
+
よろしくお願いします。
|