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?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting femto <femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> 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? Jeffrey -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
observed_classes is []. I replied earlier, but the google post forum seems to went some wrong, so makes my post unsuccesful. Sorry for that. On 11月26日, 下午4时50分, "Jeffrey L. Taylor" <r...@abluz.dyndns.org> wrote:> Quoting femto <femto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > 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? > > Jeffrey-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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?
Sorry couldn''t be more help,
Jeffrey
Quoting femto
<femtowin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> observed_classes is [].
> I replied earlier, but the google post forum seems to
> went some wrong, so makes my post unsuccesful.
> Sorry for that.
>
> On 11月26日, 下午4时50分, "Jeffrey L. Taylor"
<r...-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org> wrote:
> > Quoting femto
<femto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> >
> >
> >
> >
> >
> > > 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?
> >
> > Jeffrey
>
> --
>
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
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)>> [].sum([]) {|a| nil}=> []>> quitfawkes:audit awatkins$ sudo gem install facets Successfully installed facets-2.8.0 1 gem installed Installing ri documentation for facets-2.8.0... Installing RDoc documentation for facets-2.8.0... fawkes:audit awatkins$ irb irb(main):001:0> require ''rubygems'' => true irb(main):002:0> require ''facets'' => true irb(main):003:0> [].sum([]) {|a| nil} => 0 Andrew On Nov 27, 12:06 am, femto <femto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> observed_classes is []. > I replied earlier, but the google post forum seems to > went some wrong, so makes my post unsuccesful. > Sorry for that. > > On 11月26日, 下午4时50分, "Jeffrey L. Taylor" <r...@abluz.dyndns.org> wrote: > > > > > Quoting femto <femto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > 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? > > > Jeffrey-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.