Feedjira not adding content and author

天大地大妈咪最大 提交于 2019-12-24 07:35:22

问题


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.


回答1:


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 %>



回答2:


OK. I found where the problem was. I cloned your project and fired up. Apparently your show.html.erb page from feeds is different from the one from the article, that's why you couldn't access to entries:

Yours => From the article

If you want to see the entries first create new feed, with name and description, and for example add these links for each feed:

http://epijobs.com/rss.xml

http://feedjira.com/blog/feed.xml

When you finish adding feeds, from your terminal in root app, run cd lib/task and finally run: bundle exec rake sync:feeds as it mentioned from the article:

The rake task loops through all the Feeds stored in the database and fetches the latest content for each one. From that, loop through the new Entries, creating or updating it in the database. We are updating every time to keep up with any change in the source content.

Now, if you go to this link below for example, or through link show first feed:

http://localhost:3000/feeds/1/entries

You should be able to see all entries for feed id 1.

I hope it helps.



来源:https://stackoverflow.com/questions/41650752/feedjira-not-adding-content-and-author

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!