質問編集履歴

2

newレイアウトきかない

2019/07/16 23:37

投稿

nnnn5
nnnn5

スコア18

test CHANGED
File without changes
test CHANGED
@@ -406,7 +406,9 @@
406
406
 
407
407
 
408
408
 
409
- ```new
409
+ ```
410
+
411
+ new.html.erb
410
412
 
411
413
 
412
414
 

1

コントローラ、ビュー、ルートの追加

2019/07/16 23:37

投稿

nnnn5
nnnn5

スコア18

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 特定のページに行った時だけこのようなエラーがターミナルに出ます。
1
+ 特定のページ(`articles_controller/new`)に行った時だけこのようなエラーがターミナルに出ます。
2
2
 
3
3
  ですが、このページでのCRUD操作は可能です。
4
4
 
@@ -22,8 +22,6 @@
22
22
 
23
23
 
24
24
 
25
-
26
-
27
25
  ```ruby
28
26
 
29
27
 
@@ -54,102 +52,6 @@
54
52
 
55
53
  vendor/bundle/ruby/2.5.0/gems/warden-1.2.8/lib/warden/manager.rb:36:in `block in call'
56
54
 
57
- vendor/bundle/ruby/2.5.0/gems/warden-1.2.8/lib/warden/manager.rb:34:in `catch'
58
-
59
- vendor/bundle/ruby/2.5.0/gems/warden-1.2.8/lib/warden/manager.rb:34:in `call'
60
-
61
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/tempfile_reaper.rb:15:in `call'
62
-
63
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/etag.rb:25:in `call'
64
-
65
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/conditional_get.rb:25:in `call'
66
-
67
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/head.rb:12:in `call'
68
-
69
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
70
-
71
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:232:in `context'
72
-
73
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/session/abstract/id.rb:226:in `call'
74
-
75
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/cookies.rb:670:in `call'
76
-
77
- vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.3/lib/active_record/migration.rb:559:in `call'
78
-
79
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
80
-
81
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/callbacks.rb:98:in `run_callbacks'
82
-
83
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
84
-
85
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:14:in `call'
86
-
87
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
88
-
89
- vendor/bundle/ruby/2.5.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:135:in `call_app'
90
-
91
- vendor/bundle/ruby/2.5.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:30:in `block in call'
92
-
93
- vendor/bundle/ruby/2.5.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `catch'
94
-
95
- vendor/bundle/ruby/2.5.0/gems/web-console-3.7.0/lib/web_console/middleware.rb:20:in `call'
96
-
97
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
98
-
99
- vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/rack/logger.rb:38:in `call_app'
100
-
101
- vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/rack/logger.rb:26:in `block in call'
102
-
103
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:71:in `block in tagged'
104
-
105
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:28:in `tagged'
106
-
107
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/tagged_logging.rb:71:in `tagged'
108
-
109
- vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/rack/logger.rb:26:in `call'
110
-
111
- vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:11:in `block in call'
112
-
113
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/logger_silence.rb:21:in `silence'
114
-
115
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/logger.rb:65:in `block (3 levels) in broadcast'
116
-
117
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/logger_silence.rb:21:in `silence'
118
-
119
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/logger.rb:63:in `block (2 levels) in broadcast'
120
-
121
- vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/quiet_assets.rb:11:in `call'
122
-
123
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
124
-
125
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/request_id.rb:27:in `call'
126
-
127
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/method_override.rb:22:in `call'
128
-
129
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/runtime.rb:22:in `call'
130
-
131
- vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.3/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
132
-
133
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/executor.rb:14:in `call'
134
-
135
- vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.3/lib/action_dispatch/middleware/static.rb:127:in `call'
136
-
137
- vendor/bundle/ruby/2.5.0/gems/rack-2.0.7/lib/rack/sendfile.rb:111:in `call'
138
-
139
- vendor/bundle/ruby/2.5.0/gems/railties-5.2.3/lib/rails/engine.rb:524:in `call'
140
-
141
- vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/configuration.rb:227:in `call'
142
-
143
- vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/server.rb:660:in `handle_request'
144
-
145
- vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/server.rb:474:in `process_client'
146
-
147
- vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/server.rb:334:in `block in run'
148
-
149
- vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
150
-
151
-
152
-
153
55
 
154
56
 
155
57
  ```
@@ -158,212 +60,424 @@
158
60
 
159
61
 
160
62
 
63
+ ```gemfile
64
+
65
+
66
+
67
+ source 'https://rubygems.org'
68
+
69
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
70
+
71
+
72
+
73
+ ruby '2.5.1'
74
+
75
+
76
+
77
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
78
+
79
+ gem 'rails', '~> 5.2.2'
80
+
81
+ # Use mysql as the database for Active Record
82
+
83
+ gem 'mysql2', '>= 0.4.4', '< 0.6.0'
84
+
85
+ # Use Puma as the app server
86
+
87
+ gem 'puma', '~> 3.11'
88
+
89
+ # Use SCSS for stylesheets
90
+
91
+ gem 'sass-rails', '~> 5.0'
92
+
93
+ # Use Uglifier as compressor for JavaScript assets
94
+
95
+ gem 'uglifier', '>= 1.3.0'
96
+
97
+ # See https://github.com/rails/execjs#readme for more supported runtimes
98
+
99
+ # gem 'mini_racer', platforms: :ruby
100
+
101
+
102
+
103
+ # Use CoffeeScript for .coffee assets and views
104
+
105
+ gem 'coffee-rails', '~> 4.2'
106
+
107
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
108
+
109
+ gem 'turbolinks', '~> 5'
110
+
111
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
112
+
113
+ gem 'jbuilder', '~> 2.5'
114
+
115
+ # Use Redis adapter to run Action Cable in production
116
+
117
+ # gem 'redis', '~> 4.0'
118
+
119
+ # Use ActiveModel has_secure_password
120
+
121
+ # gem 'bcrypt', '~> 3.1.7'
122
+
123
+
124
+
125
+ # Use ActiveStorage variant
126
+
127
+ # gem 'mini_magick', '~> 4.8'
128
+
129
+
130
+
131
+ # Use Capistrano for deployment
132
+
133
+ # gem 'capistrano-rails', group: :development
134
+
135
+
136
+
137
+ # Reduces boot times through caching; required in config/boot.rb
138
+
139
+ gem 'bootsnap', '>= 1.1.0', require: false
140
+
141
+
142
+
143
+ group :development, :test do
144
+
145
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
146
+
147
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
148
+
149
+ gem 'pry-rails'
150
+
151
+ gem 'pry-byebug'
152
+
153
+ gem 'pry-doc'
154
+
155
+ end
156
+
157
+
158
+
159
+ group :development do
160
+
161
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
162
+
163
+ gem 'web-console', '>= 3.3.0'
164
+
165
+ gem 'listen', '>= 3.0.5', '< 3.2'
166
+
167
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
168
+
169
+ gem 'spring'
170
+
171
+ gem 'spring-watcher-listen', '~> 2.0.0'
172
+
173
+ gem 'letter_opener'
174
+
175
+ gem 'letter_opener_web'
176
+
177
+ end
178
+
179
+
180
+
181
+ group :test do
182
+
183
+ # Adds support for Capybara system testing and selenium driver
184
+
185
+ gem 'capybara', '>= 2.15'
186
+
187
+ gem 'selenium-webdriver'
188
+
189
+ # Easy installation and use of chromedriver to run system tests with Chrome
190
+
191
+ gem 'chromedriver-helper'
192
+
193
+ end
194
+
195
+
196
+
197
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
198
+
199
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
200
+
201
+ gem 'carrierwave'
202
+
203
+ gem 'rmagick', '~> 3.0.0'
204
+
205
+ gem 'kaminari'
206
+
207
+ gem 'jquery-rails'
208
+
209
+ gem 'jquery-ui-rails'
210
+
211
+ gem 'devise'
212
+
213
+ gem 'meta-tags'
214
+
215
+ gem 'sitemap_generator'
216
+
217
+ gem 'wysiwyg-rails'
218
+
219
+ gem "font-awesome-rails"
220
+
221
+ gem 'rinku'
222
+
223
+ # gem 'ruby-oembed'
224
+
225
+ gem 'jquery-oembed-rails', '~> 0.2.0'
226
+
227
+ gem 'rails_12factor', group: :production
228
+
229
+ gem 'fog-aws'
230
+
231
+ # gem 'fog'
232
+
233
+
234
+
161
235
  ```
162
236
 
163
- gemfile
164
-
165
-
166
-
167
- source 'https://rubygems.org'
168
-
169
- git_source(:github) { |repo| "https://github.com/#{repo}.git" }
170
-
171
-
172
-
173
- ruby '2.5.1'
174
-
175
-
176
-
177
- # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
178
-
179
- gem 'rails', '~> 5.2.2'
180
-
181
- # Use mysql as the database for Active Record
182
-
183
- gem 'mysql2', '>= 0.4.4', '< 0.6.0'
184
-
185
- # Use Puma as the app server
186
-
187
- gem 'puma', '~> 3.11'
188
-
189
- # Use SCSS for stylesheets
190
-
191
- gem 'sass-rails', '~> 5.0'
192
-
193
- # Use Uglifier as compressor for JavaScript assets
194
-
195
- gem 'uglifier', '>= 1.3.0'
196
-
197
- # See https://github.com/rails/execjs#readme for more supported runtimes
198
-
199
- # gem 'mini_racer', platforms: :ruby
200
-
201
-
202
-
203
- # Use CoffeeScript for .coffee assets and views
204
-
205
- gem 'coffee-rails', '~> 4.2'
206
-
207
- # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
208
-
209
- gem 'turbolinks', '~> 5'
210
-
211
- # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
212
-
213
- gem 'jbuilder', '~> 2.5'
214
-
215
- # Use Redis adapter to run Action Cable in production
216
-
217
- # gem 'redis', '~> 4.0'
218
-
219
- # Use ActiveModel has_secure_password
220
-
221
- # gem 'bcrypt', '~> 3.1.7'
222
-
223
-
224
-
225
- # Use ActiveStorage variant
226
-
227
- # gem 'mini_magick', '~> 4.8'
228
-
229
-
230
-
231
- # Use Capistrano for deployment
232
-
233
- # gem 'capistrano-rails', group: :development
234
-
235
-
236
-
237
- # Reduces boot times through caching; required in config/boot.rb
238
-
239
- gem 'bootsnap', '>= 1.1.0', require: false
240
-
241
-
242
-
243
- group :development, :test do
244
-
245
- # Call 'byebug' anywhere in the code to stop execution and get a debugger console
246
-
247
- gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
248
-
249
- gem 'pry-rails'
250
-
251
- gem 'pry-byebug'
252
-
253
- gem 'pry-doc'
237
+
238
+
239
+ ```route
240
+
241
+
242
+
243
+ get '*not_found' => 'application#routing_error'
244
+
245
+ post '*not_found' => 'application#routing_error'
246
+
247
+
248
+
249
+ この文を消したら今回のエラーは解決するけど新しいエラー
250
+
251
+ `ActionController::RoutingError (No route matches [GET] "/assets/languages/ja.js.map"):
252
+
253
+ `が発生
254
+
255
+
256
+
257
+ ```
258
+
259
+
260
+
261
+ ```applicationcontroller
262
+
263
+ class ApplicationController < ActionController::Base
264
+
265
+ before_action :set_current_user
266
+
267
+
268
+
269
+ protected
270
+
271
+
272
+
273
+ # 例外ハンドル
274
+
275
+ unless Rails.env.development?
276
+
277
+ # rescue_from Exception, with: :_render_500
278
+
279
+ rescue_from ActiveRecord::RecordNotFound, with: :_render_404
280
+
281
+ rescue_from ActionController::RoutingError, with: :_render_404
282
+
283
+ end
284
+
285
+
286
+
287
+ def routing_error
288
+
289
+ raise ActionController::RoutingError, params[:path]
290
+
291
+ end
292
+
293
+
294
+
295
+ private
296
+
297
+
298
+
299
+ def _render_404(e = nil)
300
+
301
+ logger.info "Rendering 404 with exception: #{e.message}" if e
302
+
303
+
304
+
305
+ if request.format.to_sym == :json
306
+
307
+ render json: { error: '404 error' }, status: :not_found
308
+
309
+ else
310
+
311
+ render template: "errors/error_404", status: :not_found, layout: 'application'
312
+
313
+ end
314
+
315
+ end
316
+
317
+
318
+
319
+ def _render_500(e = nil)
320
+
321
+ logger.error "Rendering 500 with exception: #{e.message}" if e
322
+
323
+ Airbrake.notify(e) if e # Airbrake/Errbitを使う場合はこちら
324
+
325
+
326
+
327
+ if request.format.to_sym == :json
328
+
329
+ render json: { error: '500 error' }, status: :internal_server_error
330
+
331
+ else
332
+
333
+ render template: "errors/error_500", status: :not_found, layout: 'application'
334
+
335
+ end
336
+
337
+ end
338
+
339
+
254
340
 
255
341
  end
256
342
 
257
343
 
258
344
 
345
+ ```
346
+
347
+
348
+
349
+ ```articlescontroller
350
+
351
+
352
+
353
+ class Admin::ArticlesController < ApplicationController
354
+
355
+ before_action :authenticate_user!
356
+
259
- group :development do
357
+ before_action :set_current_user
260
-
261
- # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
358
+
262
-
263
- gem 'web-console', '>= 3.3.0'
264
-
265
- gem 'listen', '>= 3.0.5', '< 3.2'
266
-
267
- # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
268
-
269
- gem 'spring'
359
+ layout "admin"
360
+
361
+
362
+
270
-
363
+ def new
364
+
365
+ @article = Article.new
366
+
367
+ end
368
+
369
+
370
+
371
+ def create
372
+
271
- gem 'spring-watcher-listen', '~> 2.0.0'
373
+ @article = Article.new(article_params)
374
+
272
-
375
+ if @article.save
376
+
377
+ redirect_to admin_articles_path
378
+
379
+ else
380
+
381
+ render :new
382
+
383
+ end
384
+
385
+ end
386
+
387
+
388
+
389
+ private
390
+
391
+
392
+
273
- gem 'letter_opener'
393
+ def article_params
274
-
394
+
275
- gem 'letter_opener_web'
395
+ params.require(:article).permit(:title, :image, :status, :position, :introduction, :content
396
+
397
+ )
398
+
399
+ end
276
400
 
277
401
  end
278
402
 
279
403
 
280
404
 
281
- group :test do
282
-
283
- # Adds support for Capybara system testing and selenium driver
284
-
285
- gem 'capybara', '>= 2.15'
286
-
287
- gem 'selenium-webdriver'
288
-
289
- # Easy installation and use of chromedriver to run system tests with Chrome
290
-
291
- gem 'chromedriver-helper'
292
-
293
- end
294
-
295
-
296
-
297
- # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
298
-
299
- gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
300
-
301
- gem 'carrierwave'
302
-
303
- gem 'rmagick', '~> 3.0.0'
304
-
305
- gem 'kaminari'
306
-
307
- gem 'jquery-rails'
308
-
309
- gem 'jquery-ui-rails'
310
-
311
- gem 'devise'
312
-
313
- gem 'meta-tags'
314
-
315
- gem 'sitemap_generator'
316
-
317
- gem 'wysiwyg-rails'
318
-
319
- gem "font-awesome-rails"
320
-
321
- gem 'rinku'
322
-
323
- # gem 'ruby-oembed'
324
-
325
- gem 'jquery-oembed-rails', '~> 0.2.0'
326
-
327
- gem 'rails_12factor', group: :production
328
-
329
- gem 'fog-aws'
330
-
331
- # gem 'fog'
332
-
333
-
334
-
335
-
336
-
337
- group :deployment do
338
-
339
- gem 'sshkit', '>= 1.9.0'
340
-
341
- gem 'sshkit-sudo', '~> 0.1.0', require: false
342
-
343
- gem 'capistrano', require: false
344
-
345
- gem 'capistrano-rbenv', github: "capistrano/rbenv", require: false
346
-
347
- gem 'capistrano-secrets-yml'
348
-
349
- gem 'capistrano-rails', require: false
350
-
351
- gem 'capistrano-rvm', require: false
352
-
353
- gem 'capistrano-bundler', require: false
354
-
355
- gem 'capistrano3-puma', require: false
356
-
357
- gem 'capistrano-faster-assets'
358
-
359
- gem 'capistrano-rails-console'
360
-
361
- gem 'rvm-capistrano'
362
-
363
- gem 'capistrano-yarn'
364
-
365
- gem 'capistrano-sidekiq', github: 'seuros/capistrano-sidekiq'
366
-
367
- end
368
-
369
405
  ```
406
+
407
+
408
+
409
+ ```new
410
+
411
+
412
+
413
+ <div class = "admin">
414
+
415
+ <h2>記事作成</h2>
416
+
417
+ <%= form_with model: [:admin, @article], local: true do |f| %>
418
+
419
+ <table class="form_area">
420
+
421
+ <tr>
422
+
423
+ <th scope="row">ステータス</th>
424
+
425
+ <td><%= f.select :status, [['公開', true], ['非公開', false]] %></td>
426
+
427
+ </tr>
428
+
429
+ <tr>
430
+
431
+ <th scope="row">メイン画像</th>
432
+
433
+ <td><%= f.file_field :image %>
434
+
435
+ <% if @article.image.present? %>
436
+
437
+ <%= image_tag @article.image_url(:thumb).to_s %><br />
438
+
439
+ <%= f.hidden_field :image_cache %>
440
+
441
+ <%= f.check_box :remove_image %><%= f.label :remove_image, '画像を削除する'%>
442
+
443
+ <% end %>
444
+
445
+ </td>
446
+
447
+ </tr>
448
+
449
+ <tr>
450
+
451
+ <th scope="row">地域</th>
452
+
453
+ <td>
454
+
455
+ <%= collection_check_boxes(:article, :pref_ids, Pref.all, :id, :name) do |b| %>
456
+
457
+ <%= b.label { b.check_box + b.text } %>
458
+
459
+ <% end %>
460
+
461
+ </td>
462
+
463
+ </tr>
464
+
465
+ <tr>
466
+
467
+ <th scope="row">タイトル</th>
468
+
469
+ <td><%= f.text_field :title , size: "90x10" %></td>
470
+
471
+ <%= error_on(:article, :title)%>
472
+
473
+ </tr>
474
+
475
+ </table>
476
+
477
+ <input id="submit" type="submit" alt="登録する" />
478
+
479
+ <% end %>
480
+
481
+
482
+
483
+ ```