class FeedController < ApplicationController
def index
@feeds = FeedItem.find(:all, :select => 'DISTINCT feed_name')
+ respond_to do |format|
+ format.html
+ format.rss { render :layout => false }
+ end
end
def show
@feed_items = FeedItem.find_all_by_feed_name(params[:feed_name])
+ redirect_to index_url if @feed_items == []
+ respond_to do |format|
+ format.html
+ format.rss { render :layout => false }
+ end
end
def update
+ item = FeedItem.find_by_feed_name_and_title(params[:feed_item][:feed_name], params[:feed_item][:title])
+ if item
+ if params[:feed_item][:description] == ''
+ item.destroy
+ else
+ item.update_attribute(:description, params[:feed_item][:description])
+ end
+ else
+ FeedItem.create(params[:feed_item])
+ end
+ redirect_to feed_url(params[:feed_item][:feed_name])
end
end
class FeedItem < ActiveRecord::Base
- require 'cgi' # needed for url decoding
+ # require 'cgi' # needed for url decoding
validates_presence_of :feed_name, :title, :description
validate :feed_name_must_be_legal
protected
def feed_name_must_be_legal
- if url_encode(feed_name) != feed_name or
- CGI::unescape(feed_name) != feed_name or
+ if Rack::Utils::escape(feed_name) != feed_name or
+ Rack::Utils::unescape(feed_name) != feed_name or
feed_name == 'index' or
feed_name == 'show' or
feed_name == 'update' or
--- /dev/null
+# index.rss.builder
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0" do
+ xml.channel do
+ xml.title "Feedcatcher"
+ xml.description "Feeds available"
+ xml.link index_url(:rss)
+
+ for feed in @feeds
+ xml.item do
+ xml.title feed.feed_name
+ xml.link feed_url(feed.feed_name, :rss)
+ xml.guid feed_url(feed.feed_name, :rss)
+ end
+ end
+ end
+end
--- /dev/null
+# index.rss.builder
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0" do
+ xml.channel do
+ xml.title @feed_items[0].feed_name
+ xml.link feed_url(@feed_items[0].feed_name, :rss)
+
+ for item in @feed_items
+ xml.item do
+ xml.title item.title
+ xml.description item.description
+ xml.guid item.id, :isPermaLink => 'false'
+ end
+ end
+ end
+end