# Aspectr and rails

**URL:** <https://www.ruby-forum.com/t/aspectr-and-rails/55203>\
**Category:** Ruby\
**Created:** [March 17, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/aspectr-and-rails/55203 "2006-03-17T21:05:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [March 17, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/aspectr-and-rails/55203/1 "2006-03-17T21:05:09Z")

</div>

Has anybody successfully used AspectR with Rails?

I would like to profile some parts of my Rails app such as accesses to  
DB, helper methods, and rendering of views. I’d like to do this in the  
live production version of the site and I’d like to turn this  
monitoring on and off at run-time.

I know I could instrument all of these methods manually and collect the  
data I want, but ideally I’d like to make no changes to the actual  
application.

So I tried using AspectR for this and it works for some methods, but  
most of the methods return this error:

#\<NoMethodError: You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.[]\>

in this method (part of aspectr) when it tries to access  
@\_\_aop\_advice\_methods:

```
  def __aop_advice_list(joinpoint, method)
	method = method.to_s
	unless (method_hash = @__aop_advice_methods[joinpoint])
  			method_hash = @__aop_advice_methods[joinpoint] = {}
	end
	unless (advice_list = method_hash[method])
  		advice_list = method_hash[method] = []
	end
	advice_list
  end

```

It seems like @\_\_aop\_advice\_methods disappears or something.

Anybody has an idea how to fix this?

Or a different way how to do the monitoring I described above?

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [March 19, 2006, 1:35am UTC](https://www.ruby-forum.com/t/aspectr-and-rails/55203/2 "2006-03-19T01:35:33Z")

</div>

AspectR is pretty old now and doesn’t appear to be actively  
maintained. It may not be compatible with more recent versions of  
Ruby. You might look at RCR 321:  
[RCR 321: Aspect Oriented Programming for Ruby](http://www.rcrchive.net/rcr/show/321%22), although if I recall  
correctly, it is proposing language changes. Still, it might give you  
ideas for doing your monitoring using existing Ruby techniques.

dean

On 3/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> def __aop_advice_list(joinpoint, method)
> 
> ```
> 
> It seems like @\_\_aop\_advice\_methods disappears or something.
> 
> Anybody has an idea how to fix this?
> 
> Or a different way how to do the monitoring I described above?
> 
> Thanks,  
> Peter

–  
Dean W.  
[http://www.aspectprogramming.com](http://www.aspectprogramming.com)  
[http://www.newaspects.com](http://www.newaspects.com)  
[http://www.contract4j.org](http://www.contract4j.org)
