163 words — 1 minutes read

Rails, Content - Type, RJS and filters

Again - one of these “it takes several hours” to find it things:

In an inherited application that I’m expanding, I was using RJS actions to handle inserts:

page.insert_html :bottom, 'info_list', :partial => 'info'

Because of some non-showing Umlauts, I switched on a filter to set the content type:

<code>
    class ApplicationController < ActionController::Base
      before_filter :set_charset

      def set_charset
        headers['Content - Type'] = "text/html; charset=8859-1"
      end
    end
</code>

with the result, that all my RJS stuff stopped working. Finally I diffed against a working copy and found the line enabling the filter. I rewrote it like this, and things started to work again

<code>
    class ApplicationController < ActionController::Base
      after_filter :set_charset

      def set_charset
        headers['Content - Type'] ||= "text/html; charset=8859-1"      
      end
    end
</code>

spot the two differences….

Also - I found out that ecto and Wordpress don’t like it at all, if you try to have something called “Content - Type” (without the spaces) in an entry and try to publish it.

Technorati Tags: rails, rubyonrails

Jens-Christian Fischer

Maker. Musician