Want more GoRails?

GoRails is packed full with 719 lessons just like this one.

Sign up to get full access or log in to your account and sit back.

Basic Authentication and RSS Feeds

June 17, 2015

Track your progress

Sign in to track your progress and access subscription-only lessons.

Log In

Your Teacher

Hi, I'm Chris. I'm the creator of GoRails, Hatchbox.io and Jumpstart. I spend my time creating tutorials and tools to help Ruby on Rails developers build apps better and faster.

About This Episode

Learn how to add authentication to an RSS feed with Rails and Devise

Notes

Resources

# index.rss.builder

title       = "GoRails Screencasts"
author      = "Chris Oliver"
description = "GoRails is a series of screencasts and guides for all aspects of Ruby on Rails. Learn how to setup your machine, build a Rails application, and deploy it to a server."
keywords    = "rails, ruby on rails, screencasts, programming, refactoring, coding"
image       = asset_url("itunes.png")

xml.instruct! :xml, version: "1.0"
xml.rss version: "2.0", "xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd", "xmlns:media" => "http://search.yahoo.com/mrss/" do
  xml.channel do
    xml.title title
    xml.link episodes_url
    xml.description description
    xml.language 'en'
    xml.pubDate @episodes.first.created_at.to_s(:rfc822)
    xml.lastBuildDate @episodes.first.created_at.to_s(:rfc822)
    xml.itunes :author, author
    xml.itunes :keywords, keywords
    xml.itunes :explicit, 'clean'
    xml.itunes :image, :href => image
    xml.itunes :owner do
      xml.itunes :name, author
      xml.itunes :email, 'chris@gorails.com'
    end
    xml.itunes :block, 'no'
    xml.itunes :category, text: 'Technology' do
      xml.itunes :category, text: 'Software How-To'
    end
    xml.itunes :category, text: 'Education' do
      xml.itunes :category, text: 'Training'
    end

    @episodes.each do  |episode|
      xml.item do
        xml.title episode.name
        xml.summary episode.description
        xml.pubDate episode.created_at.to_s(:rfc822)
        xml.enclosure url: episode.download_url, length: episode.file_size, type: 'video/mp4'
        xml.link episode_url(episode)
        xml.guid({isPermaLink: "false"}, episode.slug)
        xml.itunes :author, author
        xml.itunes :subtitle, truncate(episode.description, length: 150)
        xml.itunes :summary, episode.description
        xml.itunes :explicit, 'no'
        xml.itunes :duration, episode.length
      end
    end
  end
end

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.