0

我在哪里可以找到在 Ruby on Rails 网站中显示 RSS 提要滚动条的好教程。提要 URL 来自诸如 feedburner 之类的外部来源。feedzirra gem 可以在这里使用,但它涉及 curl 安装和其他支持 gem。我想要一些可以在没有宝石的情况下提取提要的东西。提前致谢。

4

1 回答 1

0

post_controller

def feed
       @posts = Post.where(‘status = ?’, AppConstants::APPROVAL_ACTIVE).order(“updated_at desc”).limit(10)
       posts_ids = @posts.pluck(‘id’)
       assets = Asset.where(‘ref_id IN (?) and default_image_id = ?’, posts_ids, AppConstants::DEFAULT_IMAGE_VALUE)
       @posts_default_image_hash = Hash.new
         assets.each{|asset|
             @posts_default_image_hash[asset.ref_id] = asset
        }
      respond_to do |format|
           format.html
           format.atom { render layout: false }
      end 
end

feed.atom.builder

atom_feed do |feed|
     feed.title “Domail Name!”
     feed.updated Time.now
     @posts.each do |post|
             next if post.updated_at.blank?
             url = “localhost:3000(domain Name)/#{post.id}/#{post.name}
             feed.entry post, url:url do |entry|
                   entry.title post.title
                  content = “<img src=#{@posts_default_image_hash[post.id].image_url} height=180 width=220>” + post.content
                 entry.content content, type: ‘html’
                 entry.author do |author|
                        author.name(“Author name”)
                end
           end
    end
end

路线.rb

get “feed/” => “posts#feed”, :as => :feed, :defaults => { :format => ‘atom’ }
resources :post do
end

application.html.erb(布局)

<head>
     <%= auto_discovery_link_tag :atom, “/feed” %>
</head>

footer.html.erb(无论你想要什么)

你的饲料燃烧器网址

<a href=”http://feeds.feedburner.com/abc” target=’_blank’ >
       keep some RSS feed image here </a>
于 2015-02-24T09:34:18.390 回答