LoginSignup
1
0

More than 3 years have passed since last update.

Ruby2.5.2以上でpryがどこかに飛んで行ってしまう

Posted at

起きた現象

pryが正常に動かない

class HomeController < ApplicationController
  before_action :redirect_signed_in_user, only: :welcome

  def welcome; end

  def redirect_signed_in_user
    binding.pry
    redirect_to root_url if user_signed_in?
  end
end

1度目は正常に動くが

[20, 29] in /Users/ashwinhegde/code/apps/o3_crm/app/controllers/home_controller.rb
   20:
   21:   private
   22:
   23:   def redirect_signed_in_user
   24:     binding.pry
=> 25:     redirect_to root_url if user_signed_in?
   26:   end
   27:

2度目から

[117, 126] in /Users/ashwinhegde/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/devise-4.4.3/lib/devise/controllers/helpers.rb
   117:             opts[:scope] = :#{mapping}
   118:             warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
   119:           end
   120:
   121:           def #{mapping}_signed_in?
=> 122:             !!current_#{mapping}
   123:           end
   124:
   125:           def current_#{mapping}
   126:             @current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
(byebug)

このように謎のコードに進んで行ってしまう。

解決策

byebugのリポジトリに同じ現象のissueが立てられていた。

Ruby2.5.2以上でbootsnapがインストールされている場合、pryが正常に起動しないらしい。

bootsnap/setupをdevelopmentのみでしかrequireしないようにboot.rbを修正。

boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
env = ENV['RAILS_ENV'] || 'development'

require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' if env != 'development' # Speed up boot time by caching expensive operations.
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