I've just started on Rails again and have recently followed the Sitepoint guide to building an RSS Feed app. I followed the instructions verbatim, but am getting the error undefined method 'html_safe' for nil:NilClass
. I've looked into the database and it seems Feedjira is not parsing the content
or author
attributes into the database.
After a quick google, I found the following issues on the Github page #178 and #176 dated back from August 13, but given the significant issue this causes I'm surprised there's not on it. It may be an error in my code which can be found here but I've checked and don't think it is.
Does anyone know of anything I'm doing wrong? I have altered the self.feed_classes in the feedjira documentation as suggested in Issue #176 but it still doesn't pick anything up.
RSS and Atom Feeds don't offer a content attribute. The 'content' is provided as 'summary' attribute. So change
local_entry.update_attributes(content: entry.content, author: entry.author, url: entry.url, published: entry.published)
to
local_entry.update_attributes(content: entry.summary, author: entry.author, url: entry.url, published: entry.published)
Nevertheless, NewsFeeds are very fickle things. So you shouldn't rely on the existence of single attributes.
Have a look at your show.html.erb
<%= @entry.content.html_safe %>
You could for example use the safe navigation operator
<%= @entry&.content&.html_safe %>
Or inform the user, that no content is present
<% unless @entry.content.nil? %>
<%= @entry.content.html_safe %>
<% end %>