Rails ATOM Invalid Encoding Error when using Kramdown for markdown

78 Views Asked by At

I'm attempting to generate an RSS/Atom feed within my application.

At the moment it all works if I pass in the raw markdown but once I use Kramdown I get the following error:

undefined method 'valid_encoding?' for nil:NilClass

index.atom.builder

atom_feed do |feed|
  feed.title(@user.display_name)
  feed.updated(@ungrouped_digests[0].send_at) if @ungrouped_digests.length > 0

  @ungrouped_digests.each do |post|
    feed.entry(post) do |entry|
      entry.title(post.subject)
      entry.content(render("post", post: post), type: 'html')
      entry.author do |author|
        author.name(@user.full_name)
      end
    end
  end
end

_post.atom.erb

<%= Kramdown::Document.new(post.markdown_body).to_html.html_safe %>

If I switch the above to just <%= post.markdown_body %> it renders the raw markdown but obviously that's not what I want here.

0

There are 0 best solutions below