LoginSignup
0
1

More than 3 years have passed since last update.

RuntimeErrorで画像投稿ができなかった場合の対処法

Posted at

背景

Refileなどの画像投稿が出来るgemを導入し、画像を実際に格納してみたら
RuntimeErrorとされた。よくあることらしいので備忘録も含めて。

使用環境
ruby 2.7.2 Rails 6.0.3.4

対処法

エラー文をよく読むとそこまで難しくない。そのままの通り実行することする。

RuntimeError at / Refile.secret_key was not set.

Please add the following to your Refile configuration and restart your application:

Refile.secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

このRefile.secret_key='XXX'をそのままコピー。
時間を置くとkeyが変わるので注意。

/config/initializers/application_controller_renderer.rb
# Be sure to restart your server when you modify this file.

# ActiveSupport::Reloader.to_prepare do
#   ApplicationController.renderer.defaults.merge!(
#     http_host: 'example.org',
#     https: false
#   )
# end

#以下を貼り付ける
Refile.secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

Railsを再起動し、リロードし直すと無事画像が投稿されたのが確認された。

0
1
1

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
1