Geek Blog for Little Red String

Geek stuff, amature programming, Linux, Ruby, open source

Facebooker and Open_ID_Authentication Plugins Conflict

I found that the Rails plugin open_id_authentication1 was throwing an error when I had facebooker2 in my /vendor/plugins directory.

The issue is that Facebooker rewrites some Rail’s code in ActionController:

module ::ActionController
  class AbstractRequest                         
    def relative_url_root
      Facebooker.path_prefix
    end                                         
  end

...

This method (relative_url_root) returns a nil if you haven’t set a Facebooker path_prefix and open_id_authentication never expects to get a nil from this method. This caused an error:

Type Error

can't convert nil into String

vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:150:in `+'
...

I looked at Err The Blog’s post about the Evil Twin Plugin technique for hacking up plugins. There are two ways to solve the problem with this technique.


Fix It From the Facebooker Side
Create a folder in your /vendor/plugins directory called “facebooker_hacks” and create a file called “init.rb” in that folder. Here’s what goes in init.rb:

Facebooker.module_eval do 
  def self.path_prefix
    @path_prefix || '' # I added the || ''
  end
end

Make sure you restart your server after making the change.


Fix It From the Open_ID_Authentication Side
This time create a directory called “open_id_authentication_hacks” in /vendor/plugins with the “init.rb” file in it. In init.rb:

OpenIdAuthentication.module_eval do 
  private
  def requested_url
    "#{request.protocol + request.host_with_port + request.relative_url_root.to_s + request.path}"
  end
end

This makes the method a little less picky by adding “to_s” to relative_url_root. Again be sure to restart your server.


What I Did
I chose to do the second hack because Facebooker is under heavy development while Open_ID_Authentication is not. I figured that messing with Open_ID_Authentication was less likely to cause a problem in the future as I keep updating my plugins.

Footnotes

1 SVN revision: 9250

2 About version 0.95. Cloned from Vitality’s commit:c2f1ab9a36018f6b5c6352d79bfc540f45fc5c3c