Feedjira 没有添加内容和作者 [英] Feedjira not adding content and author

查看:34
本文介绍了Feedjira 没有添加内容和作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚再次开始使用 Rails,最近关注了 构建 RSS Feed 应用程序的站点指南.我逐字按照说明进行操作,但收到错误 undefined method 'html_safe' for nil:NilClass.我查看了数据库,似乎 Feedjira 没有将 contentauthor 属性解析到数据库中.

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.

在快速谷歌之后,我在 Github 页面上发现了以下问题 #178#176 可追溯到 8 月 13 日,但考虑到这导致我的重大问题很惊讶上面没有.这可能是我的代码中的错误,可以在 here 中找到,但我已经检查过但没有认为是.

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.

有人知道我做错了什么吗?我已经按照 问题 #176 中的建议更改了 feedjira 文档中的 self.feed_classes,但是它仍然没有捡到任何东西.

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 和 Atom 提要不提供内容属性.内容"作为摘要"属性提供.所以改变

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)

local_entry.update_attributes(content: entry.summary, author: entry.author, url: entry.url, published: entry.published)

尽管如此,NewsFeed 是非常善变的东西.所以你不应该依赖单一属性的存在.

Nevertheless, NewsFeeds are very fickle things. So you shouldn't rely on the existence of single attributes.

看看你的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 %>

这篇关于Feedjira 没有添加内容和作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆