Hello all, while I'm using acts_as_audited(on jruby platform),
after vendored the acts_as_audited, it reports some error,
line 167,
# Start observing the declared classes and their subclasses.
def initialize
Set.new(observed_classes + observed_subclasses).each { |klass|
add_observer! klass } #this line
end
after some trace shows this one, when observed_classes is empty, will
return 0(Fixnum) causes the
above line to report error,
def observed_subclasses
observed_classes.sum() { |klass| klass.send(:subclasses) }
end
so I changed it to this:
def observed_subclasses
#observed_classes.sum() { |klass| klass.send(:subclasses) }
result =
observed_classes.each do |klass|
result += klass.send(:subclasses)
end
Hello all, while I'm using acts_as_audited(on jruby platform),
after vendored the acts_as_audited, it reports some error,
line 167,
# Start observing the declared classes and their subclasses.
def initialize
Set.new(observed_classes + observed_subclasses).each { |klass|
add_observer! klass } #this line
end
after some trace shows this one, when observed_classes is empty, will
return 0(Fixnum) causes the
above line to report error,
def observed_subclasses
observed_classes.sum() { |klass| klass.send(:subclasses) }
end
so I changed it to this:
def observed_subclasses
#observed_classes.sum() { |klass| klass.send(:subclasses) }
result =
observed_classes.each do |klass|
result += klass.send(:subclasses)
end
end
It this a bug?
What is definition of observed_classes? When there are no observed classes,
does it return or nil?
Many gems do not work properly with jRuby. You might check with jRuby Website
and the acts_as_audited Website. I don't have a jRuby installation handy.
My only suggestion is back way off on the functionality until it behaves as
expected and then add functionality back in with lots of puts statements
and/or logger statements. Array#sum() is a Rails extension. You might try
using inject.
E.g. observed_classes.inject(){|a, i| a + i.send(:subclasses)}
It is implied, but not stated. Does your rewrite of observed_subclasses()
work as expected?
So I had the same problem, turns out that it was because we had ruby
facets installed alongside acts_as_audited: http://facets.rubyforge.org/apidoc/index.html.
The issue being is that facets implements its own sum, which overrode
rails internal sum. Rails internal sum will return 0 on an empty
array, while facets returns 0:
fawkes:audit awatkins$ ruby script/console
Loading development environment (Rails 2.3.3)