Rails - render: content_type has no effect

I am developing a Ruby / Rails application that deletes another website and feeds an RSS feed with data.

Since this application is built on Heroku, I generate the RSS feed through the controller instead of dumping it into the file system and serving it as an asset.

However, when I set the hash render :content_type

, there is no effect. The response content type remains text/plain

.

news

action FeedController

def news
  do_scrape
  @posts = UbuEntry.all(:order => "created_at DESC", :limit => 400)
  render :layout => false, :content_type => Mime::RSS
end

      

Full routes.rb

UbuWebRSS::Application.routes.draw do
  root :to => 'index#index'
  scope :format => true, :constraints => { :format => 'rss' } do
    get 'feed/news' => 'feed#news'
  end
end

      

You can see the result here:

http://www.ubuwebrss.com/feed/news.rss

And the complete source code:

https://github.com/freen/ubuwebrss/

I looked at Google and StackOverflow but didn't figure out what I was doing wrong.

Any tips? Thank!

FYI:

View script: /app/views/feed/news.rss.builder :

xml.instruct! :xml, :version => "1.0" 
xml.rss :version => "2.0" do
  xml.channel do
    xml.title "UbuWeb"
    xml.description "UbuWeb is a completely independent resource dedicated to all strains of the avant-garde, ethnopoetics, and outsider arts."
    xml.link 'http://www.ubu.com'

    for post in @posts
      xml.item do
        xml.title post.title

        description = post.description.to_s
        unless description.empty?
          # Manually add description for custom HTML sanitizing
          description = @sanitizer_basic.clean(description)
          xml << " " * 6
          xml << "<description><![CDATA[" + description + "]]></description>\n"
        end

        xml.pubDate post.created_at.to_s(:rfc822)
        xml.link post.href
        xml.guid post.href
      end
    end
  end
end

      

+3


source to share


1 answer


It seems to be returning the correct content-type (c curl -i <url>

):

HTTP/1.1 200 OK 
Server: nginx
Date: Mon, 04 Feb 2013 00:10:05 GMT
Content-Type: application/rss+xml; charset=utf-8
Content-Length: 121890
Connection: keep-alive
X-Ua-Compatible: IE=Edge,chrome=1
Etag: "74ebbfe3182fef13d8a737580453f688"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 9377e469ffad158b2480a3f6b2f2866c
X-Runtime: 0.748709
X-Rack-Cache: miss

      



This may be a bug in Chrome, not your application.

+4


source







All Articles