0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ruby on Rails6】gem "devise" のviewsのpasswordsだけが編集できない。

Last updated at Posted at 2021-03-14

【Rails6】gem "devise" のviewsのpasswordsだけが編集できない。

↑記事で解決できました。
しかし、私の場合passwordsのviewsだけhtml.erb編集が反映されなかったので事象を記録します。

環境 Ruby 2.6.6p146/Rails 6.0.3

通常通りdeviseを導入後、viewを編集。なぜかpasswordsだけ編集できずググって解決。

結論

config/initializers/devise.rb

devise.rb
  # ==> Scopes configuration
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
  # "users/sessions/new". It's turned off by default because it's slower if you
  # are using only default views.
  # config.scoped_views = false

のコメントアウト箇所…

devise.rb
 # ==> Scopes configuration
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
  # "users/sessions/new". It's turned off by default because it's slower if you
  # are using only default views.
  config.scoped_views = true 

config.scoped_views = true にしてください。
そのままのコメントアウトだとconfig.scoped_views = falseなので注意です。

その後ターミナルで

rails s でサーバー再起動も忘れずに。
※僕は再起動しないと反映されませんでした。

これにて解決。

ここからが??な事象です。もし、謎を知っている方がいたら教えていただきたいです。

反映されない該当箇所をブラウザリロードをすると、ターミナル表示が

 Started GET "/users/password/new" for ::1 at 2021-03-14 11:49:26 +0900
Processing by Devise::PasswordsController#new as HTML
  Rendering /Users/sxkx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/devise-i18n-1.9.2/app/views/devise/passwords/new.html.erb within layouts/application
  Rendered /Users/sxkx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/devise-i18n-1.9.2/app/views/devise/shared/_error_messages.html.erb (Duration: 0.1ms | Allocations: 15)
  Rendered /Users/sxkx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/devise-i18n-1.9.2/app/views/devise/shared/_links.html.erb (Duration: 0.4ms | Allocations: 246)
  Rendered /Users/sxkx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/devise-i18n-1.9.2/app/views/devise/passwords/new.html.erb within layouts/application (Duration: 2.5ms | Allocations: 863)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered layouts/_header.html.erb (Duration: 0.3ms | Allocations: 119)
  Rendered layouts/_sidemenu.html.erb (Duration: 0.2ms | Allocations: 135)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 28ms (Views: 26.4ms | ActiveRecord: 0.0ms | Allocations: 11089)

Rendering /Users/sxkx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/devise-i18n-1.9.2/app/views/devise/passwords/new.html.erb within layouts/application
??なんだか長い…。 devise-i18n…. 日本語化のために入れたgemが悪さをしている??

devise.rb
  config.scoped_views = true 

をすると

Started GET "/users/password/new" for ::1 at 2021-03-14 11:54:00 +0900
Processing by Devise::PasswordsController#new as HTML
  Rendering users/passwords/new.html.erb within layouts/application
  Rendered users/shared/_error_messages.html.erb (Duration: 0.1ms | Allocations: 15)
  Rendered users/shared/_links.html.erb (Duration: 0.9ms | Allocations: 225)
  Rendered users/passwords/new.html.erb within layouts/application (Duration: 4.7ms | Allocations: 1058)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered layouts/_header.html.erb (Duration: 0.5ms | Allocations: 119)
  Rendered layouts/_sidemenu.html.erb (Duration: 0.3ms | Allocations: 135)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 41ms (Views: 37.7ms | ActiveRecord: 0.0ms | Allocations: 12092)

Rendering users/passwords/new.html.erb within layouts/application
うん。なんかちゃんと狙いのファイルを拾ってくれていそう。

スコープを指定したから、しっかりできた感じなんですね。
ただなぜpasswordsだけがそうなったのかは謎です。

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?