Subscribe: townx - Ruby Tuesday: RSS feeds in Rails - Comments
http://townx.org/crss/node/471
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
action  belongs  feed feed  feed  glad  lot  model  owner  person photo  person  photo photo  photo  photos  recent photos  xml 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: townx - Ruby Tuesday: RSS feeds in Rails - Comments

townx - Ruby Tuesday: RSS feeds in Rails - Comments



Comments for "Ruby Tuesday: RSS feeds in Rails"



 



Correct !!

Mon, 10 May 2010 01:00:46 -0400

good one..

This is a very useful feature of ROR so that we can use associations and relationship to get the data of the expressed models..
:)




How do you add belongs_to associations into builder

Wed, 19 Aug 2009 14:27:02 -0400

How would you do a belongs_to association. For example if a person is in a photo and the photo could contain many people how do you display person.photo.title with xml builder. Displaying the data from a has_many relationship is simple using for person in @photo.people but for a belongs_to relationship I cant figure out how to do @person.photo.title(obviously this isn't working for me) in xml builder. This example is a little strange but for my purposes this is the type relationship i'm trying to display in xml. any ideas?

Assumption: person only shows up in one picture.

class Person < ActiveRecord::Base
belongs_to :photo
end

class Photo < ActiveRecord::Base
has_may :people
end




Not sure about that, as the

Wed, 27 May 2009 04:30:05 -0400

Not sure about that, as the source for the RSS feed comes from the database. Are you caching db objects?




My rssfeed is not getting updatde

Tue, 19 May 2009 07:35:28 -0400

Hi i have adding rssfeed in my browser from my application. If add new updates those updates are not getting updated in my rssfeed...
Can you say me whats going wrong..

Thanks in advance...




You're welcome, glad it was

Thu, 04 Sep 2008 15:00:08 -0400

You're welcome, glad it was useful.




Thanks a lot for the example.

Wed, 03 Sep 2008 21:50:43 -0400

Thanks a lot for the example.




The simplest approach would

Thu, 26 Jun 2008 02:24:09 -0400

The simplest approach would be to give each user an authentication token (e.g. a sha1 hash of their username + password + salt) which they append to the RSS URL to get an authenticated feed. The RSS action only returns the feed if the token is present. That would probably do it.




What about authentication?

Tue, 24 Jun 2008 12:50:39 -0400

In my site a user has to login. I've made it work so that the RSS feed is for them, but I'm not sure how to get them to be able to loggin before hand. Any ideas? I'm just using basic salt/md5 hashing and sessions to store the user.




h not necessary

Mon, 23 Jun 2008 19:30:29 -0400

You don't need to use the h function here. Stuff you put in is automatically encoded.




Glad you found it useful.

Thu, 06 Sep 2007 10:32:23 -0400

Glad you found it useful. Happy RSS-feeding!




Thnks Helps me a lot

Thu, 23 Aug 2007 08:44:43 -0400

Hey thank u very much this helps me a lot.




Hang on a minute: you're a

Thu, 02 Aug 2007 10:38:24 -0400

Hang on a minute: you're a tricksy spambot, aren't you? Go on, admit it.




You're welcome, glad it was

Sun, 22 Jul 2007 02:31:43 -0400

You're welcome, glad it was helpful.




You're quite right. I've

Sun, 22 Jul 2007 02:31:24 -0400

You're quite right. I've included your refinement above.




Great Post

Sun, 22 Jul 2007 01:39:52 -0400

This was a great example. Thank you very much.

Do you need to parse the date? I'm just using
myobj.created_at.rfc822




Ruby Tuesday: RSS feeds in Rails

Tue, 12 Dec 2006 16:35:00 -0500

Yesterday, I mentioned I have added RSS feed capabilities to FlickrLilli. I thought it might be worth sharing my experiences of this, as it took me a good couple of hours to iron out the wrinkles and get a valid feed. Update: Thanks to Thomas Hurst (see comments) for pointing out that I can just use the output from the existing partial and escape it again. Existing components I had a lot of code for fetching photos from Flickr and displaying them as HTML: I wanted to reuse these as much as possible. The examples below simplify, as FlickrLilli is a special case and doesn't have a database back-end; for the example, I have assumed a photo database which stores Flickr-like photo objects. The model FlickrLilli doesn't use ActiveRecord, but has objects corresponding to photos from Flickr. For the purposes of this example, let's assume a photo actually corresponds to a table in the database called photos, and has a model that looks like this: class Photo < ActiveRecord::Base has_and_belongs_to_many :tags belongs_to :owner # Show tag names in a human-readable string. # (Thanks to Tim [see comments] for reminding me of this syntax.) def tag_str tags.map(&:name).join(", ") end end And that the model supplies these attributes (which mirrors Flickr metadata on a photo): title description date_taken image_url (the URL to the actual photo graphic file) tags (returns an array of Tag model objects) licence owner (an instance of an Owner model object, with a username and homepage URL) The standard partial for rendering a photo FlickrLilli uses a single partial to render a photo as HTML in different contexts (app/views/main/_metadata.rhtml). Paraphrasing a bit, this looks like:

<%=h photo.title %>

<%= image_tag(photo.image_url) %>

Tags: <%=h photo.tag_str %>

Licence: <%= photo.licence %>

Date and time taken: <%= photo.date_taken %>

Owner: <%= link_to photo.owner.username, photo.owner.homepage %>

Description:
<%=h photo.description %>

The RSS feed generator Given these two existing components (a model and an HTML partial for a photo), I set about writing my feed generator. It needed: A controller action to manage the feed An RXML template for rendering it (RXML uses Builder to generate XML output for controller actions) A route which makes it convenient to download the raw feed XML as an XML file with a .xml suffix The controller action for the RSS feed This was pretty quick to write. Again, using a simplified version for the purposes of exposition, I added the action to my MainController class (in app/controllers/main_controller.rb): def rss # Get the 10 most recent photos @photos = Photo.find :all, :limit => 10, :order => 'date_taken DESC' # Title for the RSS feed @feed_title = "10 most recent photos" # Get the absolute URL which produces the feed @feed_url = "http://" + request.host_with_port + request.request_uri # Description of the feed as a whole @feed_description = "10 most recent photos" # Set the content type to the standard one for RSS response.headers['Content-Type'] = 'application/rss+xml' # Render the feed using an RXML template render :action => 'rss', :layout => false end There are a couple of key things [...]


Media Files:
http://www.townx.org/files/rss.zip