Nil location provided. Can't build URI for Rails 5.2

1.8k Views Asked by At

I'm quite new to Ruby programming. Upgrading app from Rails 4 to 5.2. Getting below error while running RSpec. Rails version and other changes are done. Not sure how to resolve the error.

Failure/Error: = image_tag current_user.gravatar_url, class: 'gravatar'

ActionView::Template::Error: Nil location provided. Can't build URI.
      # ./app/views/layouts/_navigation.html.haml:25:in `_app_views_layouts__navigation_html_haml___4566101014686141882_47249923845420'
      # ./app/views/layouts/application.html.haml:15:in `_app_views_layouts_application_html_haml__778403214308649385_47249873224260'
      # ./spec/controllers/clones_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
      # ------------------
      # --- Caused by: ---
      # ArgumentError:
      #   Nil location provided. Can't build URI.
      #   ./app/views/layouts/_navigation.html.haml:25:in `_app_views_layouts__navigation_html_haml__

Gravatar defination in user.rb:

def gravatar_url
  md5 = Digest::MD5.hexdigest(email)
  "https://www.gravatar.com/avatar/#{md5}"
end

_navigation.html.haml file:

%ul.nav.navbar-nav.pull-right{:style => 'font-size:12px'}
        - if user_signed_in?
          %li.dropdown.profile
            %a.dropdown-toggle{:'data-toggle' => 'dropdown'}
              = image_tag current_user.gravatar_url, class: 'gravatar'
              = current_user.name
              %b.caret
            %ul.dropdown-menu
              %li= link_to 'Permissions', command_permissions_path if can? :index, CommandPermission
              %li= link_to 'Logout', logout_path, :method => :delete
1

There are 1 best solutions below

0
ARK On

Your action gravatar_url in user.rb is returning nil because at some point it gets some wrong value from md5. You need to observe the string returned by gravatar_url (at every cycle if in a loop) and figure out why it is returning nil. That is the issue.