public
Description: Small application that lets you generate an rss feed for any page
Clone URL: git://github.com/jduff/rssanything.git
John Duff (author)
Wed May 14 19:40:51 -0700 2008
commit  1c8d151140f9170ab9b89f29f67cae7139c75b01
tree    decf0b316c615081f0510071ce6a62b3317808f5
parent  3c21f9b2c72a3331e266567746278014b906c6b2
rssanything / app / controllers / feeds_controller.rb
100644 40 lines (27 sloc) 0.978 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class FeedsController < ApplicationController
  
  def index
    @feeds = Feed.find(:all)
  end
  
  def new
    
    feed = Feed.new(:title => params[:url].gsub('[', '[@'), :link => params[:url].gsub('[', '[@'),
            :link_regexp => params[:link].gsub('[', '[@'), :title_regexp => params[:title].gsub('[', '[@'),
            :content_regexp => params[:content].gsub('[', '[@'))
            
    feed.save!
    
    Feed.refresh params[:id]
    
    redirect_to :action => :show, :id => feed.id
  end
  
  def show
    @feed = Feed.find_by_id(params[:id])
    
    return redirect_and_flash({:action => :index}, "That feed could not be found") unless @feed
    
    @items = Item.find(:all, :conditions => ["feed_id = ?", params[:id]],
      :order => "created_at DESC")
    
    respond_to do |format|
      format.xml
    end
  end
  
  private
  def redirect_and_flash(url, message, severity = :error)
    flash[severity] = message
    redirect_to url
  end
  
end