簡體   English   中英

使用Rails atom_feed helper在Atom Feed中呈現HTML內容

[英]Rendering HTML-Content in Atom Feed with Rails atom_feed helper

我對(相當未記錄的)atom_feed幫助器有一些問題。

我很樂意做這樣的事情:

for blogpost in @blogposts
  feed.entry(blogpost) do |entry|
    entry.title(blogpost.title)
    entry.content(render :partial => '...', :object => blogpost), :type => 'html')
  end
end 

但這似乎不起作用,我不知道如何呈現HTML而不是一些內聯文本!

我們舉一個例子:

entry.content (<div style=" ... "> + article.body + </div> + <div style=" ... "> + <img src=" + article.img.url + ..... )

直接在index.atom.builder中編寫和設置內容非常煩人。

有沒有辦法在該上下文中呈現html-partial?

有人能幫助我嗎?

謝謝分配PascalTurbo

我最近做了這個並把我的發現放到了一個帖子里,見這里: http//www.communityguides.eu/articles/14

一個相當簡單的版本就是這樣,鏈接中還有更多:

應用程序/視圖/文章/ 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

這看起來像一個老bug。 我發現的最佳解決方案是使用.atom.erb擴展復制部分。 例如

_inner_slider.html.erb成為_inner_slider.atom.erb

這是因為Rails正在尋找某種格式。

這個解決方案根本不是DRY,其他替代品非常受歡迎。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM