【问题标题】:How to link rss feed to a url如何将 rss 提要链接到 url
【发布时间】:2013-07-24 16:44:36
【问题描述】:

我正在使用 Ruby 的 RSS 类在 Sinatra 应用程序中生成 RSS 提要。每个用户的提要都是唯一的。如何将提要连接到一个 URL,以便用户可以使用他们的 RSS 阅读器进行订阅,并自动接收新的提要更新?

【问题讨论】:

    标签: ruby rss sinatra


    【解决方案1】:

    无耻地从http://recipes.sinatrarb.com/p/views/rss_feed_with_builder盗取

    安装或添加Builder gem:

    # add to Gemfile and run `bundle`...
    gem 'builder'
    
    # ... or install system-wide
    $ gem install builder  
    

    为您的应用/控制器添加适当的路由:

    # in app.rb
    get '/rss' do
      @posts = # ... find posts
      builder :rss
    end
    

    创建视图以显示 RSS 提要:

    # in views/rss.builder
    xml.instruct! :xml, :version => '1.0'
    xml.rss :version => "2.0" do
      xml.channel do
        xml.title "Cool Website News"
        xml.description "The latest news from the coolest website on the net!"
        xml.link "http://my-cool-website-dot.com"
    
        @posts.each do |post|
          xml.item do
            xml.title post.title
            xml.link "http://my-cool-website-dot.com/posts/#{post.id}"
            xml.description post.body
            xml.pubDate Time.parse(post.created_at.to_s).rfc822()
            xml.guid "http://my-cool-website-dot.com/posts/#{post.id}"
          end
        end
      end
    end
    

    进一步阅读:

    【讨论】:

      猜你喜欢
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 2016-11-27
      • 2011-03-10
      • 1970-01-01
      • 2013-10-15
      相关资源
      最近更新 更多