Ok, so I''m trying to add an rss feed onto my blog. I found this page in the wiki: http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml And as per it''s instructions, I have this action: def rss @photos = Photo.find(:all) render_without_layout end and then I have this view (app/views/photos/photosml.rxml): xml.instruct! xml.photos{ for photo in @photos xml.photo do xml.id(photo.id) xml.created_on(photo.created_on) end end } But when I try to access photos/rss, I just get this error: Template is missing Missing template ./script/../config/..//app/views//photos/rss.rhtml So obviously I''m missing some detail somewhere that tells rails to use the .rxml file instead of looking for rhtml... unfortunately I can''t find anything else in the wiki. -- Urban Artography http://artography.ath.cx
On 4/26/05, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> and then I have this view (app/views/photos/photosml.rxml): > > > But when I try to access photos/rss, I just get this error: > > Template is missing > > Missing template ./script/../config/..//app/views//photos/rss.rhtml > > So obviously I''m missing some detail somewhere that tells rails to use > the .rxml file instead of looking for rhtml... unfortunately I can''t > find anything else in the wiki.You do not need to do anything special to tell rails to look for rxml, you call it the same way you would call a render of a rhtml file. Take a look at the render_* methods inside of ActiveController. Also why not download one of the great open-source rails applications that provides an rss feed, like Typo, and see how its done. Josh
In your case you should just rename your photosml.rxml to mathe the controller method''s name. You have to call it rss.rxml and everything should work fine. On 4/27/05, Rob Park <rbpark-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, so I''m trying to add an rss feed onto my blog. I found this page > in the wiki: > > http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml > > And as per it''s instructions, I have this action: > > def rss > @photos = Photo.find(:all) > render_without_layout > end > > and then I have this view (app/views/photos/photosml.rxml): > > xml.instruct! > xml.photos{ > for photo in @photos > xml.photo do > xml.id(photo.id) > xml.created_on(photo.created_on) > end > end > } > > But when I try to access photos/rss, I just get this error: > > Template is missing > > Missing template ./script/../config/..//app/views//photos/rss.rhtml > > So obviously I''m missing some detail somewhere that tells rails to use > the .rxml file instead of looking for rhtml... unfortunately I can''t > find anything else in the wiki. > > -- > Urban Artography > http://artography.ath.cx > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
You are nearly there, just tweak it to: def rss @photos = Photo.find(:all) render_action ''rss'' end (If you want to use xml.link(...) don''t forget to use @url.rewrite, rather than just @url) Cheers Tom Rob Park wrote:>Ok, so I''m trying to add an rss feed onto my blog. I found this page >in the wiki: > >http://wiki.rubyonrails.com/rails/show/HowtoGenerateXml > >And as per it''s instructions, I have this action: > > def rss > @photos = Photo.find(:all) > render_without_layout > end > >and then I have this view (app/views/photos/photosml.rxml): > >xml.instruct! >xml.photos{ > for photo in @photos > xml.photo do > xml.id(photo.id) > xml.created_on(photo.created_on) > end > end >} > >But when I try to access photos/rss, I just get this error: > > Template is missing > > Missing template ./script/../config/..//app/views//photos/rss.rhtml > >So obviously I''m missing some detail somewhere that tells rails to use >the .rxml file instead of looking for rhtml... unfortunately I can''t >find anything else in the wiki. > > >-- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.10.3 - Release Date: 25/04/2005
On 4/26/05, Josh Knowles <joshknowles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> why not download one of the great open-source rails applications that > provides an rss feed, like Typo, and see how its done.Well that''s the best idea I''ve read all day long. Looks like rails just automatically looks for views as "app/views/controller/action.r(html|xml)". Not sure why the wiki suggests action "rss" would look for view "hatsml.rxml", without saying you''d need anything special for rails to actually find this file. "rss.rxml" works fine. -- Urban Artography http://artography.ath.cx
I suppose it''d be a good idea to post what I actually ended up doing, so that somebody else searching the list archives will be able to find the solution ;) On 4/27/05, Tom Ayerst <twa-pCGr9Sw2R8Y@public.gmane.org> wrote:> You are nearly there, just tweak it to: > > def rss > @photos = Photo.find(:all) > render_action ''rss'' > endHmmm, isn''t that redundant since the action is already called "rss"? IIRC render_action is only needed if you want to render a different template than the one that rails would grab automagically. So this is my action, anyway: def rss @headers["Content-Type"] = "text/xml; charset=utf-8" @photos = Photo.find(:all, :order => ''created_on DESC'', :limit => 10) render_without_layout end And this is my view (app/views/photos/rss.rxml): xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.rss "version"=>"2.0", "xmlns:dc"=>"http://purl.org/dc/elements/1.1/" do xml.channel do xml.title "Urban Artography" xml.link "http://artography.ath.cx" xml.language "en-us" xml.ttl "1440" #1440 minutes in one day xml.description "Artistic photos of urban spaces..." for photo in @photos xml.item do xml.title photo.created_on xml.description photo.caption xml.pubDate Time.parse(photo.created_on.to_s).httpdate xml.link "http://artography.ath.cx/" + photo.created_on.to_s end end end end (I need the Time.parse bit because created_on is of type "date" in my db instead of "timestamp"... if anybody knows of an easier way to convert Date objects into Time objects, I''d really appreciate that. thanks) -- Urban Artography http://artography.ath.cx