Is there a to_rss for respond_to blocks in 1.2

Hi,

I am looking to create an rss feed using rails 1.2, is there a way to
easily do this by using somthing like
format.rss { render :rss => @blogs.to_rss }

cheers

I use resource_feeder

http://dev.rubyonrails.org/svn/rails/plugins/resource_feeder/

NOTE: This plugin depends on the latest version of simply_helpful,
available here:
http://dev.rubyonrails.org/svn/rails/plugins/simply_helpful/

Here are a some resources for usage:

http://www.ryandaigle.com/articles/2006/09/14/whats-new-in-edge-rails-get-your-rss-atom-feeds-for-free

  • Nicholas

Nicholas Barthelemy wrote:

I use resource_feeder

http://dev.rubyonrails.org/svn/rails/plugins/resource_feeder/

NOTE: This plugin depends on the latest version of simply_helpful,
available here:
http://dev.rubyonrails.org/svn/rails/plugins/simply_helpful/

Here are a some resources for usage:

how to publish feeds with resource_feeder « evan weaver
http://www.ryandaigle.com/articles/2006/09/14/whats-new-in-edge-rails-get-your-rss-atom-feeds-for-free

  • Nicholas

thanks :slight_smile:

Ruby has rss functionality built in.
See: http://www.rubyrss.com/

you can do something like this:

in YourController:
def index
respond_to do |format|
format.rss { render :xml => YourModel.to_rss }
end
end

in YourModel:

def self.to_rss()
rss = RSS::Rss.new( “2.0” )
channel = RSS::Rss::Channel.new
channel.title = "Your Title
channel.description = “Your Description.”
channel.link = “http://www.yoururl.whatever
rss.channel = channel

selected_items = self.find( :all, :order => "created_on

DESC", :limit => 15)
selected_items.each do |selected|
item = RSS::Rss::Channel::Item.new
item.title = selected.headline
item.description = selected.body
item.link = “some sort of link to the item”
item.pubDate = selected.created_on
channel.items << item
end

return rss.to_s

end

in your environment.rb:
require ‘rss/2.0’

  • Brian

Ruby has RSS functionality built in.
see http://www.rubyrss.com/.

I did something like this.

in YourController’s respond:

respond_to do |format|
  format.rss  { render :xml => SomeModel.to_rss }
end

in SomeModel:
def self.to_rss()
rss = RSS::Rss.new( “2.0” )
channel = RSS::Rss::Channel.new
channel.title = “Your Title goes here”
channel.description = “Your Description goes here”
channel.link = “http://www.yourlinkgoeshere.com
rss.channel = channel

selected_posts = self.find( :all, :order => "created_on

DESC", :limit => 15) // or some other querry
selected_posts.each do |post|
item = RSS::Rss::Channel::Item.new
item.title = post.headline
item.description = post.body
item.link = “http://yourlinkgoeshere.com/posts/#{post.id}
item.pubDate = post.created_on
channel.items << item
end

return rss.to_s

end

in the environment.rb you need to add:
require ‘rss/2.0’

hope this helps