Rendering HTML-Content in Atom Feed with Rails atom_feed helper
I've got some problems with the (fairly undocumented) atom_feed helper.
I'ld love to do something like this:
for blogpost in @blogposts
feed.entry(blogpost) do |entry|
entry.title(blogpost.title)
entry.content(render :partial => '...', :object => blogpost), :type => 'html')
end
end
But that doesn't seem to work and I have no Idea how to render HTML instead of some inline text!
Let's make an example:
entry.content (<div style=" ... "> + article.body + </div> + <div style=" ... "> + <开发者_C百科;img src=" + article.img.url + ..... )
Writing and styling up the content directly in the index.atom.builder is really annoying.
Isn't there a way to render a html-partial in that context?
Could somebody help me.
Thanks allot PascalTurbo
I did this recently and put my findings into a post, see here: http://www.communityguides.eu/articles/14
A fairly simple version would be like this, there is more in the link:
app/views/articles/index.atom.builder
atom_feed do |feed|
feed.title "Title"
feed.updated @articles.first.created_at
@articles.each do |article|
feed.entry article do |entry|
entry.title article.titl
entry.content article.body, :type => 'html'
entry.author do |author|
author.name article.author
end
end
end
end
This looks like an old bug. Best solution I found is to make a duplicate of the partial with the .atom.erb extentions. E.g.
_inner_slider.html.erb became _inner_slider.atom.erb
This is because Rails is looking for a certain format.
This solution is not DRY at all and other alternatives are more than welcome.
精彩评论