LoginSignup
0
0

More than 1 year has passed since last update.

uninitialized constant Rack::Protection

Posted at

概要

Railsアプリの開発でSidekiqを使う場面があると思います。
その際にハマった問題についてまとめていきます。

敬意

sidekiq web interface show Forbidden when I try delete or post operations. · Issue #1289 · mperham/sidekiqに紹介されている方法でRackを用いて特定のドメインのみsidekiqを扱えるように設定をした際にこの問題が起きました。

エラー内容

sidekiqをv6.0.xを使って、先ほどのいるとタイトルのエラーが発生します。

config/routes.rb
require 'sidekiq/web'

Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]
Sidekiq::Web.set :sessions, Rails.application.config.session_options
Sidekiq::Web.class_eval do
  use Rack::Protection, origin_whitelist: ['https://your.domain'] # resolve Rack Protection HttpOrigin
end
Gemfile
gem 'sidekiq', '~> 6.0.7'
# 例えばRailsを起動すると
$ rails s

Exiting
Traceback (most recent call last):
...
/home/web/config/routes.rb:8:in `block (2 levels) in <main>': uninitialized constant Rack::Protection (NameError)

原因

2年前の対応によりv6.1.0以降からrack-protectionの依存を無くした対応が入ったため。

対策

Gemfile
# 追記
gem 'rack-protection'

まとめ

滅多に起きたいことかもですが、古いアプリで使っていた設定を新規アプリで同じように設定して使おうとした際にバージョン指定していないとこのエラーにハマるかと。(てかハマった笑)

 

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