rails: undefined method `find_script_name' for nil:NilClass

Steps to reproduce

  1. update from rails 6.0.x to 6.1.3.2
  2. access running application from webbrowser or execute integration specs

after a restart of the rails server, it sometimes works. then it is raises the exception again after a few requests.

Expected behavior

path helper should not raise any exceptions 😃

Actual behavior

exception is raised:

undefined method find_script_name’ for nil:NilClass`

     ActionView::Template::Error:
       undefined method `find_script_name' for nil:NilClass
     # ./app/views/session/local/new.html.haml:9:in `_app_views_session_local_new_html_haml__3352878839210418481_44280'
     # /opt/bundle/ruby/2.7.0/gems/sentry-raven-3.1.2/lib/raven/integrations/rails/controller_transaction.rb:7:in `block in included'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
     # /opt/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:37:in `call_app'
     # /opt/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:26:in `block in call'
     # /opt/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/rack/logger.rb:26:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
     # /opt/bundle/ruby/2.7.0/gems/sentry-raven-3.1.2/lib/raven/integrations/rack.rb:51:in `call'
     # /opt/bundle/ruby/2.7.0/gems/railties-6.1.3.2/lib/rails/engine.rb:539:in `call'
     # /opt/bundle/ruby/2.7.0/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
     # /opt/bundle/ruby/2.7.0/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
     # /opt/bundle/ruby/2.7.0/gems/rack-test-1.1.0/lib/rack/test.rb:119:in `request'
     # ./spec/integration/root_login_spec.rb:32:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # NoMethodError:
     #   undefined method `find_script_name' for nil:NilClass
     #   ./app/views/session/local/new.html.haml:9:in `_app_views_session_local_new_html_haml__3352878839210418481_44280'

System configuration

Rails version: 6.1.3.2

Ruby version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

Project: https://github.com/puzzle/cryptopus/tree/feature/374-rails-update

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

hi there! I’m looking into this, but if you change session_local_path to Rails.application.routes.url_helpers.session_local_path in your view, it works for now if you want to continue on with your upgrade (not the greatest solution I know). I noticed that you have some other unrelated test failures as well. Also, you put 2.7.2 for your ruby version but your .ruby-version file on your branch in your project has 2.5.

While debugging I noticed that this codepath was getting hit, which @tenderlove added some time ago. Will try to look into it more later unless anyone has an answer as to what’s going on.

@pixiitech I’m having this same error in Rails 7

I was able to resolve the problem with a temporary fix. It may not be the most elegant solution, but it’s temporal until the core team can address the issue.

module ApplicationHelper
# app/helpers/application_helper.rb

  Rails.application.routes.url_helpers.instance_methods.each do |method|
    if method.to_s.include?("_path")
      define_method(method) do |*args, **kwargs|
        Rails.application.routes.url_helpers.send(method, *args, **kwargs)
      end
    end
  end

end

@23tux @obromios I’m also experiencing a similar issue to yours, where I sometimes encounter errors when running a web application on the server. However, this error is not common and I am not sure what specific error it is, so I do not know how to solve it.

My solution is simply restarting the web server, which usually resolves the issue. If either of you has any solutions, please share them with me. Thank you.

For context, I am using Ruby 2.7.2 and Rails 6.1.6.1.