Changes between Version 6 and Version 7 of UsingFeedsInCode


Ignore:
Timestamp:
Jul 20, 2006, 2:59:05 PM (15 years ago)
Author:
nick
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UsingFeedsInCode

    v6 v7  
    88
    99== Ruby On Rails ==
     10
     11An example for grabbing the nodes in a Locale, and outputting the nodes titles and links follows.
     12
     13{{{
     14require 'rexml/document'
     15require 'open-uri'
     16include REXML
     17
     18class LocalIndexController < ApplicationController
     19
     20def showindex
     21    feed_url = 'http://cotswolds.openguides.org/wiki/wiki.cgi?action=index;index_type=locale;index_value=Charlbury;format=rss'
     22    output = "<h1>My RSS Reader</h1>"
     23    open(feed_url) do |http|
     24        response = http.read
     25        doc = Document.new(response)
     26
     27        title = doc.root.elements["//title"].text
     28        puts title
     29
     30        output += "<h2>Title: #{title}</h2><div>"
     31
     32        i = 0
     33        doc.each_element("//item") do |node|
     34            node_title = node.elements["title"].text
     35            node_link = node.elements["link"].text
     36
     37            output += "#{i+1}. <a href='#{node_link}'>#{node_title}</a><br />"
     38            i = i + 1
     39        end
     40
     41        output += "</div>"
     42    end
     43    render_text output
     44end
     45end
     46}}}
     47
     48This should be added to routes.rb something like:
     49{{{
     50   map.connect '/nodesInLocale', :controller => "localeIndex", :action => 'showindex'
     51}}}
    1052
    1153== !ColdFusion ==