Archive

Archive for the ‘Uncategorized’ Category

Feedzirra on Rails3

February 10th, 2010

I am using Feedzirra in one of my projects. I was trying to experiment my app with Rails3 and found the following issue when using Feedzirra. This is just a hack to get it to work, I am sure there are better ways to solve it. The issue is Feedzirra uses Loofah library for html scrubbing. Loofah makes some assumptions about the Rails framework as in code on line# 86 here

if defined? Rails.configuration and Rails.configuration.frameworks.include?([:active_record]) # rails 2.1 and later
  Rails.configuration.after_initialize do
    require 'loofah/active_record'
    require 'loofah/xss_foliate'
  end
elsif defined? ActiveRecord::Base # rails 2.0
  require 'loofah/active_record'
  require 'loofah/xss_foliate'
end

As per new changes in Rails3 (framework agnostic), config.frameworks is deprecated causing the following error config.frameworks in no longer supported. See the generated config/boot.rb for steps on how to limit the frameworks that will be loaded (RuntimeError).

To get around this I have made the following change

loofah.rb line# 86

begin
    if defined? ActiveRecord::Base
      require 'loofah/active_record'
      require 'loofah/xss_foliate'
    elsif defined? Rails.configuration and Rails.configuration.frameworks.include?([:active_record]) # rails 2.1 and later
      Rails.configuration.after_initialize do
        require 'loofah/active_record'
        require 'loofah/xss_foliate'
      end
    end
rescue
  #handle the error accordingly
end

Add new gem group to Gemfile of rails3 app

group :after_initialize do
    gem "feedzirra", :git => "git://github.com/chrismsnz/feedzirra.git"
end

Now tell Bundler to load feedzirra after application initializtion by changing application.rb of rails3 app like this

Bundler.require :after_initialize

BTW I used the forked Feedzirra branch of chrismsnz available here instead of original pauldix tree.

Hope this helps someone.

Uncategorized