Closed ceceliahavens closed 8 years ago
Does master give you the same problem? What's the stack trace look like. Walk through the lines of code where it's failing. It looks like current_user
is nil
and we're trying to access it's gravatar.
If it is trying to access the current user and the user is nil, I guess my confusion is still the same because the capability to sign out using identical code,not in the dropdown works perfectly with the gravatar.
The master gives the same error.
undefined method `gravatar_url' for nil:NilClass Extracted source (around line #4):
%h1.text-center User Dashboard .booyah-box.col-xs-10.col-xs-offset-1 %h2 = image_tag selected_user.gravatar_url(default: "retro"), alt: selected_user.name, class: "gravatar" = selected_user.email %hr %h4 Name:   #{selected_user.name}
app/views/users/show.html.haml:4:in `_app_views_users_show_html_haml___1026086878302774684_34585520'
This indicates that on this line:
= image_tag selected_user.gravatar_url(default: "retro"), alt: selected_user.name, class: "gravatar"
selected_user
is nil. You should take a look inside the controller and figure out why that's the case.
I suspect I'm not explaining my question very well. I apologize. Clarity is apparently a problem for me today, (this is not my first failure in communication today) I think I may just resort to interpretive dancing to communicate from now on.
My question is how can this code's use in the dropdown menu trigger this error when the code is identical and acceptable one line down outside of the dropdown?
It doesn't trigger the parameters problem when it is not in the dropdown? The logic of selected_user inside the controller is only problematic if the dropdown is used. What is it about the dropdown that causes the selected_user method inside the controller to be unable to work with the dropdown? I looked over the controller and the stack trace before I asked for assistance, I am just having a hard time understanding how or why the drop down causes the issue. I think I understand what, I just don't understand why.
Why is it pulling "sign_out" as the param id:? why wouldn't it have been doing that all along? and I dont' understand what it has to do with gravatar?
My hunch is the problem isn't with the code you added, but with the existing codebase (checkout master - you may see the same problem). As you haven't changed line 4 of the file, I believe either you're on a URL, which is causing the selected_user
to be nil
.
The real problem isn't in the HTML, but it's why is selected_user
is nil
in the file here: users/show.html.haml
.
Also try it out on a page that isn't the user dashboard page.
If this isn't helpful, feel free to take a look at a different ticket and we can review this on our call on Thursday.
@kenmazaika,
When I put the path for the sign out in the drop down menu I get a very confusing error that is seemingly unrelated to the changes I made.
%ul.dropdown-menu %li %ul.dropdown-menu %li %a{:href => user_path(current_user)} My Profile %li %a{:href => destroy_user_session_path, :method => :delete} Sign out %li %a{:href => new_user_session_path} Sign in %li.divider %li %a{:href => "#"} Separated link
I get the error undefined method `gravatar_url' for nil:NilClass
I am not sure how or why gravatar would be linked to a drop down menu, and all other paths work correctly.
Additionally I am having some difficulties with the drop down logic to only show the sign out when you are signed in and only show the sign in when you are signed out. If I put and if/else statement into the dropdown menu it stops performing as a drop down menu. Do you have code examples handy of drop down menus? I have been looking around but I haven't quite figured out what to do. I hate to be hung up on such a small task but that is life and that is how I'm rolling right now.
Gracias