質問編集履歴
2
endが抜けていた部分を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -166,6 +166,8 @@
|
|
166
166
|
|
167
167
|
render :edit
|
168
168
|
|
169
|
+
end
|
170
|
+
|
169
171
|
end
|
170
172
|
|
171
173
|
|
1
refererを読むタイミングをリダイレクト前に変更した
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
referer_uri = URI.parse(request.referer)
|
62
62
|
|
63
|
-
if referer_uri.path
|
63
|
+
if referer_uri.path == posts_path
|
64
64
|
|
65
65
|
...
|
66
66
|
|
@@ -146,76 +146,70 @@
|
|
146
146
|
|
147
147
|
|
148
148
|
|
149
|
-
if referer_uri.path != posts_path
|
150
|
-
|
151
|
-
|
149
|
+
if @post.update(post_params)
|
150
|
+
|
152
|
-
|
151
|
+
if referer_uri.path == posts_path
|
152
|
+
|
153
|
-
redirect_to
|
153
|
+
redirect_to posts_path, notice: 'Post was successfully updated.'
|
154
154
|
|
155
155
|
else
|
156
156
|
|
157
|
-
re
|
157
|
+
redirect_to @post, notice: 'Post was successfully updated.'
|
158
158
|
|
159
159
|
end
|
160
160
|
|
161
|
+
elsif referer_uri.path == posts_path
|
162
|
+
|
163
|
+
redirect_to posts_path, flash: { error: @post.flash_error_hash }
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
render :edit
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
def post_params
|
178
|
+
|
179
|
+
params.require(:post).permit(:title)
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
`post.rb`
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
|
195
|
+
class Post < ApplicationRecord
|
196
|
+
|
197
|
+
validates :title, presence: true
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
def if_eq_add_errors_to_self(flash_error_post)
|
202
|
+
|
203
|
+
return unless id == flash_error_post['id']
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
flash_error_post['details'].each do |col_key, details|
|
208
|
+
|
209
|
+
details.each { |detail| errors.add(col_key, detail['error'].to_sym) }
|
210
|
+
|
161
211
|
end
|
162
212
|
|
163
|
-
|
164
|
-
|
165
|
-
if @post.update(post_params)
|
166
|
-
|
167
|
-
redirect_to posts_path, notice: 'Post was successfully updated.'
|
168
|
-
|
169
|
-
else
|
170
|
-
|
171
|
-
redirect_to posts_path, flash: { error: @post.flash_error_hash }
|
172
|
-
|
173
|
-
end
|
174
|
-
|
175
|
-
end
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
private
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
def post_params
|
184
|
-
|
185
|
-
params.require(:post).permit(:title)
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
```
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
`post.rb`
|
198
|
-
|
199
|
-
```ruby
|
200
|
-
|
201
|
-
class Post < ApplicationRecord
|
202
|
-
|
203
|
-
validates :title, presence: true
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
def if_eq_add_errors_to_self(flash_error_post)
|
208
|
-
|
209
|
-
return unless id == flash_error_post['id']
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
flash_error_post['details'].each do |col_key, details|
|
214
|
-
|
215
|
-
details.each { |detail| errors.add(col_key, detail['error'].to_sym) }
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
213
|
end
|
220
214
|
|
221
215
|
|