1
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 1 year has passed since last update.

【Rails】refileでのエラー解消(Refile.secret_key was not set.)

Posted at

この記事の目的

  • 現在学習中のRailsについての理解とアウトプット、振り返り用
  • Railsのrefileで起きたエラーの解消について

バージョン

ruby 3.2.0
Rails 7.0.4.3

起きたエラーについて

Railsのrefileを使用して画像投稿機能を作成している際に下記のエラーが発生しました。

Refile.secret_key was not set.

Please add the following to your Refile configuration and restart your application:
Refile.secret_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

スクリーンショット 2023-04-10 22.33.27.png

原因

refileのsecret_keyが登録されていないということみたいです

解消方法

  • refileのsecret_keyを設定したあげる

refileのsecret_keyを設定

config/initializers/application_controller_renderer.rbにエラー画面で出てきたRefile.secret_keyを下記のように設定して下さい。
Rails7からはconfig/initializers/配下にapplication_controller_renderer.rbがデフォルトでないのでない場合は追加して下さい。追加後はrails sで再度サーバーを起動して下さい

config/initializers/application_controller_renderer.rb
Refile.secret_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

サーバーを起動後確認すると無事画像が更新できていました!!
スクリーンショット 2023-04-10 22.43.27.png

参考

【プログラミング入門】Ruby on Rails でウェブアプリを作ってみよう ~ PART 2(実装①)
rails 7.0ではconfig/initializers配下のファイルが少なくなっている

1
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
1
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?