i'm trying create rss feed news posts, i've googled , come code:
def feed @posts = news.all(:conditions => "#{settings.show} = 1", :select => "id, title, heading, content, date_posted", :order => "date_posted desc") respond_to |format| format.rss { render :layout => false } end end then in file called "feed.rss.builder" have this:
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" xml.channel xml.title "your blog title" xml.description "a blog software , chocolate" xml.link posts_url post in @posts xml.item xml.title post.title xml.description post.content xml.pubdate post.date_posted.to_s(:rfc822) xml.link post_url(post) xml.guid post_url(post) end end end end i've added routes file match "/news/feed" => "aboutus#feed" when go page nothing rendered..
this code ended with:
def news @news = news.find(:all, :order => "date_posted desc", :conditions => "#{settings.show} = 1") render :template => 'about-us/news/feed.rss.builder', :layout => false end and:
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" xml.channel xml.title "news" xml.description "description" xml.link "/news" post in @news xml.item xml.title post.title xml.description post.content xml.pubdate post.date_posted.to_s(:rfc822) xml.link "/news/#{post.reference}" xml.guid "/news/#{post.reference}" xml.icon "/favicon.ico" end end end end
Comments
Post a Comment