Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionView::Template::Error: undefined method `name' for nil:NilClass #5153

Open
sentry-io bot opened this issue Mar 18, 2019 · 16 comments
Open

ActionView::Template::Error: undefined method `name' for nil:NilClass #5153

sentry-io bot opened this issue Mar 18, 2019 · 16 comments
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed inspection

Comments

@sentry-io
Copy link

sentry-io bot commented Mar 18, 2019

Sentry Issue: PLOTS2-2T

NoMethodError: undefined method `name' for nil:NilClass
  app/views/tag/show/_contributors.html.erb:6:in `_app_views_tag_show__contributors_html_erb__960191231886015937_69873440052920'
    <h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/#{@user.name}") %> </h3>
  app/views/tag/show.html.erb:6:in `_app_views_tag_show_html_erb__385204970133675734_69873440114860'
    <%= render partial: 'tag/show/contributors' %>
  app/controllers/map_controller.rb:220:in `tag'
    render template: 'tag/show'
...
(153 additional frame(s) were not displayed)

ActionView::Template::Error: undefined method `name' for nil:NilClass

ActionView::Template::Error: undefined method `name' for nil:NilClass
@madeofhuman
Copy link
Contributor

I'd like to work on this. @gauravano @jywarren

@jywarren
Copy link
Member

jywarren commented Mar 19, 2019 via email

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

I'm currently tracing based on the error log to see if I can reproduce this, but more information on reproducing this error will be really appreciated as it'll save time.

I've narrowed it down, @jywarren. Working on a fix now.

@grvsachdeva grvsachdeva added bug the issue is regarding one of our programs which faces problems when a certain task is executed inspection labels Mar 19, 2019
@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

@jywarren, @gauravano please correct me if I'm wrong, but I don't think this part

by <%= link_to(@user.name,"/profile/#{@user.name}") %>

is necessary in the h3. If I understand correctly, the page is meant to display all maps containing any of the tags supplied in the url param, and they can be of different authors, so there can't be a single author name in the header. Instead, there should be a table displaying the maps (or a re-use of the maps index template).

@jywarren
Copy link
Member

jywarren commented Mar 19, 2019 via email

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

Hmm.... let me see....

This is the controller method that renders the view:

def tag
    set_sidebar :tags, [params[:id]], note_count: 20

    @tagnames = params[:id].split(',')
    nids = Tag.find_nodes_by_type(@tagnames, 'map', 20).collect(&:nid)
    @notes = Node.paginate(page: params[:page])
      .where('nid in (?)', nids)
      .order('nid DESC')

    @title = @tagnames.join(', ') if @tagnames
    @unpaginated = true
    render template: 'tag/show'
end

It's returning a list of 'notes' (should be nodes, btw) that isn't filtered by any user. So, to get the author of a 'note' (node), we'd have to do note.author.username (after iterating over the list).

The partial that should display the maps is currently called directly in the view like so:

<%= render partial: 'tag/show/contributors' %>

without being wrapped in an iterator.

This is what makes me think the page should display a list of maps not filtered by any author. And if each map is clicked, it then renders the page for that map.

Screenshot 2019-03-19 at 9 46 16 PM

@jywarren

Besides, user is nil, so calling user.username instead will still throw the error.

@jywarren
Copy link
Member

Ah yes, you're totally right! 🎉

I think we need to further refine the conditional on these lines, because you're right, it's getting stuck because it is wrongly assuming this is the 'for this author' view:

<% if params[:action] == 'show'&& @node_type=="contributors" %>
<h3><%= raw t('tag.contributors.contributors_for', :tag_name => params[:id]) %></h3>
<% elsif params[:action] == 'show' %>
<h3><%= raw t('tag.show.notes_tagged', tag: params[:id]) %></h3>
<% else %>
<h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/#{@user.name}") %> </h3>
<% end %>

Could we show the <h3> Notes on <%= params[:id] %> by <%= link_to(@user.name,"/profile/#{@user.name}") %> </h3> line with an additional condition that @user has to exist?

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

Yeah, we could do that, but there's no other place that's calling that partial, so I don't think the by user part is needed. The 'for this author' view uses a different template.

@jywarren
Copy link
Member

jywarren commented Mar 19, 2019 via email

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

I'll check it out. 😄

Edit: Yup! Seems it's using the template. My bad.

On another note, what's up with that bug #5099? The error occurs on Chrome but not on other browsers like Opera or Safari.

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 19, 2019

@jywarren I've fixed this but I'm yet to raise a PR for it. It seems that by fixing this, I also fixed this FTO issue that I created, and which has been assigned to a newcomer to work on. However, it was assigned a week ago but there's been no update from the person on it since. What do you suggest?

@jywarren
Copy link
Member

jywarren commented Mar 20, 2019 via email

@madeofhuman
Copy link
Contributor

madeofhuman commented Mar 20, 2019

@jywarren I need your thoughts on this, please:

How do I display the returned maps after searching by tags? I have two thoughts:

  1. render it in the full maps/index template

Screenshot 2019-03-20 at 1 53 04 PM

  1. render it in the map/maps partial inside the tag/show template and conditionally remove the extra UI elements

Screenshot 2019-03-20 at 12 11 55 AM

@jywarren
Copy link
Member

Hmm. I guess I think #2 would be best, but keep in mind that we are slowly seeking to convert all maps into note records, so we're mostly looking to stabilize this part of the code until that larger project has time to be completed. #4072

Thank you! Big codebases like these always have these big slow-moving projects, so your work is extra critical to keep things working as they progress!

@jywarren
Copy link
Member

So, in sum, i guess, we will eventually be showing maps alongside notes, using the notes template, so let's do something pragmatic here to solve the issue at hand until that happens. Thanks again!

@madeofhuman
Copy link
Contributor

Sure thing. I'm really glad to be of help.

@stale stale bot added the stale label Oct 7, 2020
@publiclab publiclab deleted a comment from stale bot Oct 8, 2020
@stale stale bot removed the stale label Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed inspection
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants