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

Created on 18 Mar 2019  Â·  16Comments  Â·  Source: publiclab/plots2

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
bug inspection

Most helpful comment

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

All 16 comments

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

oh that'd be great! Is there enough information to work with?

On Tue, Mar 19, 2019 at 11:25 AM CJ Odina notifications@github.com wrote:

I'd like to work on this. @gauravano https://github.com/gauravano
@jywarren https://github.com/jywarren

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5153#issuecomment-474421994,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ6H_47oxfJb3CYuU1bwAEs1xL7Q1ks5vYQEvgaJpZM4b596P
.

~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.

@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).

Hmm, it's possible that this section is used for a version of the page
showing only one author. What we probably need to do is change "user.name"
to "user.username"?

On Tue, Mar 19, 2019 at 1:54 PM CJ Odina notifications@github.com wrote:

@jywarren https://github.com/jywarren 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 notes 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.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5153#issuecomment-474496330,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ2ySxTW0vPPVJSpBln6M3MyjFacQks5vYSRPgaJpZM4b596P
.

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.

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:

https://github.com/publiclab/plots2/blob/4fc2e9f0d54485dbfebb0d3ab070d9d2ce9497c7/app/views/tag/show/_contributors.html.erb#L1-L7

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?

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.

actually i think it may be connected to an existing issue #5099 -- i
/believe/ that page will require this h3. Is that OK? Thank you!

On Tue, Mar 19, 2019 at 5:00 PM CJ Odina notifications@github.com wrote:

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.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5153#issuecomment-474582129,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJ-Rj7tCWpKSE51Gg8v9uOOXWrjQRks5vYU-2gaJpZM4b596P
.

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.

@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?

hmm, well, very nice of you to look out for them. Maybe leave a comment
asking if they need any help? I'm happy to delay merging this until that's
done if it helps. Thank you!

On Tue, Mar 19, 2019 at 7:38 PM CJ Odina notifications@github.com wrote:

@jywarren https://github.com/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 https://github.com/publiclab/plots2/issues/5021 that I created,
and which has been assigned to someone to work on. Although, it was
assigned last week but there's been no update from the person. What do you
suggest?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/publiclab/plots2/issues/5153#issuecomment-474626116,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABfJzUEisZvbamVckiMuLt5VuqqPbcpks5vYXTtgaJpZM4b596P
.

@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

  2. 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

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. https://github.com/publiclab/plots2/issues/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!

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!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jywarren picture jywarren  Â·  3Comments

RuthNjeri picture RuthNjeri  Â·  3Comments

grvsachdeva picture grvsachdeva  Â·  3Comments

milaaraujo picture milaaraujo  Â·  3Comments

first-timers[bot] picture first-timers[bot]  Â·  3Comments