[英]Tutorial to build rss feed scroller in ruby on rails
在哪里可以找到好的教程来在Ruby on Rails网站上显示RSS feed滚动条。 Feed URL来自外部来源,例如feedburner。 feedzirra宝石可以在这里使用,但是它需要卷曲安装和其他辅助宝石。 我想要一些可以不带宝石的饲料。 提前致谢。
posts_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
routes.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>
foooter.html.erb (无论您要在哪里)
您的Feed刻录机网址
<a href=”http://feeds.feedburner.com/abc” target=’_blank’ >
keep some RSS feed image here </a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.