Conflicting module names when using multiple gems (in my case: social_stream and rails3_acts_as_paranoid)

652 Views Asked by At

I am using those two gems: social_stream (rails engine) and rails3_acts_as_paranoid (lib).

When I try to see the homepage, I get the following error:

NameError in Home#index

Showing /home/pinouchon/code/sharewizz/webapp/app/views/home/index.html.erb where line #25 raised: uninitialized constant ActsAsParanoid::Relation::Public Extracted source (around line #25):

22: 
23: <%= 
24:     render :partial => "activities/index",
25:          :locals => { :activities => current_subject.wall(:home).page(params[:page]),
26:                             :owner => current_subject }
27:  %>
28: 

Full trace:

social_stream-base (0.21.0) app/models/relation.rb:159:in `ids_shared_with'
app/models/activity.rb:70:in `block in <class:Activity>'
activerecord (3.2.2) lib/active_record/scoping/named.rb:180:in `call'
activerecord (3.2.2) lib/active_record/scoping/named.rb:180:in `block (2 levels) in scope'
# ...

I think it is because 2 modules defined by those gems share the same name: Relation.

In /home/pinouchon/.rvm/gems/ruby-1.9.3-p392@project/gems/rails3_acts_as_paranoid-0.2.5/lib/acts_as_paranoid/relation.rb:

module ActsAsParanoid
  module Relation
  # ...

In /home/pinouchon/.rvm/gems/ruby-1.9.3-p392@project/gems/social_stream-base-0.21.0/app/models/relation.rb:

class Relation < ActiveRecord::Base
  #...
  def ids_shared_with(subject)
      # line 159:
      ids = [Relation::Public.instance.id]
      # ...

In /home/pinouchon/.rvm/gems/ruby-1.9.3-p392@project/gems/social_stream-base-0.21.0/app/models/relation/public.rb:

class Relation::Public < Relation::Single
  # ...

Before, I was using only social stream, no there were no conflicting modules names. Now, it is as if ActsAsParanoid::Relation is replacing Relation, hence the problem in .../social_stream/.../relation.rb line 159.

But what's surprising is that the Relation module of rails3_acts_as_paranoid is nicely namespaced in module ActsAsParanoid. So it shouldn't interfere with the Relation of social_stream defined in global scope, yet it is. I am probably missing something.

Am I right about what's causing the error ? Is there any way I can fix that ?

1

There are 1 best solutions below

0
On

By overwriting the model relation defined by social_stream (copying the file to app/models), and changing the line 159:

ids = [Relation::Public.instance.id]

to

ids = [::Relation::Public.instance.id]

Everything works fine. I have no idea why I have to explicitly specify to use the global scope here. I am still open to an explanation or a better answer.