Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rails makes the code sharing of rss feed

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "rails making rss feed code sharing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Methods:

It is you who piece together the format of RSS XML and output it. And set HTTP Header, mark content-type as application/XML, common code:

# Post_controller::feed () def feed require "rss" articles = Article.find: all,: order = > 'post_date DESC' : limit = > 10 feed = RSS::Maker.make do | maker | maker.channel.title = "Gang of Technology" maker.channel.description = "Gang of Technology site" maker.channel.link = "http://up-u.com" maker.items.do_sort = true articles.each do | article | item = maker.items.new_item item.link =" http://www.***.com/archives/#{article.id}" item.title = article.title item. Date = article.post_date item.description = "" end end send_data feed.to_s : type = > "application/rss+xml",: disposition = > 'inline' end method B: Rails Controller- > Action Code: copy the code as follows: # Post_controller::feed def feed @ posts=Post.find: all,:limit= > "id desc" end erb template: xml.instruct! Xml.rss ("version" = > "2.0"," xmlns:dc "= >" http://purl.org/dc/elements/1.1/") do xml.channel do xml.title "renlu.xu 's blog" xml.link (url_for (: action= > "start") : only_path= > false) xml.description "My life My love" xml.language "zh_CN" xml.ttl 60 for event in @ posts do xml.item do xml.title (event.title) xml.description (event.body) xml.pubDate (event.created_at.to_s (: rfc822)) xml.guid (event.id) xml.link ("http:// …" .. # {event.id} ") this is the content of end end end end" rails making rss feed Code sharing ". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report