# Is there a to\_rss for respond\_to blocks in 1.2

**URL:** <https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760>\
**Category:** Rails\
**Created:** [April 23, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760 "2007-04-23T22:44:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 23, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760/1 "2007-04-23T22:44:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 23, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760/2 "2007-04-23T23:42:02Z")

</div>

I use resource\_feeder

[http://dev.rubyonrails.org/svn/rails/plugins/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/](http://dev.rubyonrails.org/svn/rails/plugins/simply_helpful/)

Here are a some resources for usage:

> **[how to publish feeds with resource\_feeder](https://blog.evanweaver.com/2006/09/19/how-to-publish-feeds-with-resource_feeder/)**
>
> The resource\_feeder plugin, along with simply\_helpful, recently snuck into edge Rails, courtesy of DHH. They’re nice. resource\_feeder lets a controller return a well-formed RSS or Atom feed for any…

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

- Nicholas

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [April 24, 2007, 12:31am UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760/3 "2007-04-24T00:31:40Z")

</div>

Nicholas Barthelemy wrote:

> I use resource\_feeder
> 
> [http://dev.rubyonrails.org/svn/rails/plugins/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/](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://blog.evanweaver.com/articles/2006/09/19/how-to-publish-feeds-with-resource_feeder)  
> [http://www.ryandaigle.com/articles/2006/09/14/whats-new-in-edge-rails-get-your-rss-atom-feeds-for-free](http://www.ryandaigle.com/articles/2006/09/14/whats-new-in-edge-rails-get-your-rss-atom-feeds-for-free)
> 
> - Nicholas

thanks 🙂

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [May 16, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760/4 "2007-05-16T17:42:47Z")

</div>

Ruby has rss functionality built in.  
See: [http://www.rubyrss.com/](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](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

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [May 16, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/is-there-a-to-rss-for-respond-to-blocks-in-1-2/92760/5 "2007-05-16T15:53:27Z")

</div>

Ruby has RSS functionality built in.  
see [http://www.rubyrss.com/](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](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}](http://yourlinkgoeshere.com/posts/#%7Bpost.id%7D)”  
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
