Sentry Issue: PLOTS2-18G
This seems to affect visiting the wiki root path at https://publiclab.org/wiki/, but may interact with being redirected to the https://publiclab.org/join/ path?
NoMethodError: undefined method `username' for nil:NilClass
app/views/wiki/_header.html.erb:37:
<li style='list-style: none;'><a href='/profile/<%= author.username %>' style='color: #009bff;'>@<%= author.username %></a></li>
app/views/wiki/_header.html.erb:36:in `each'
<% @node.authors.each do |author| %>
app/views/wiki/_header.html.erb:36:
<% @node.authors.each do |author| %>
app/views/wiki/show.html.erb:25:
<%= render partial: "wiki/header" %>
app/controllers/wiki_controller.rb:269:in `root'
render template: 'wiki/show'
...
(158 additional frame(s) were not displayed)
ActionView::Template::Error: undefined method `username' for nil:NilClass
@cesswairimu @RuthNjeri Is this because some wikis don't have an author? So we can just do <%=author.username if author%>.
Hi @gaurav2699 that could be a reason, the best way to find out is testing it locally, Instead of the if statement, you could use the safe navigation symbol that Ruby has https://stackoverflow.com/questions/36812647/what-does-ampersand-dot-mean-in-ruby
Hey @RuthNjeri, yeah I tried this locally, so the uid of a node cannot be null, but this error comes when I put the uid as the id of the user that does not exist in the users table. This is probably because the user has deleted his/her account but the record created by it has not been deleted. We can change this line to ensure that this error doesn't come in the future
https://github.com/publiclab/plots2/blob/93415927cfbbf10bf42bff24eb542395e00f7103/app/models/user.rb#L49
to has_many :node, foreign_key: 'uid', dependent: :destroy and similarly for the node_revision statement.
Hey @RuthNjeri, I made the required changes. Please review my PR. Thanks a lot!
@gaurav2699 yeah I think we can do that or even use the safe nil navigator &. https://mitrev.net/ruby/2015/11/13/the-operator-in-ruby/ ... did you want to work on this? I could convert it to a FTO otherwise, Thanks
Hey @cesswairimu, I have already linked a PR that should solve this issue. I think this issue arose because the user who created the wiki has deleted his/her account but the wiki is not deleted because we don't have on delete cascade for the relationship. Thank you!
Most helpful comment
Hey @cesswairimu, I have already linked a PR that should solve this issue. I think this issue arose because the user who created the wiki has deleted his/her account but the wiki is not deleted because we don't have on delete cascade for the relationship. Thank you!