# My first plugin =\> my first Stack level too deep

**URL:** <https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195>\
**Category:** Rails\
**Created:** [May 5, 2009, 10:02am UTC](https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195 "2009-05-05T10:02:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [May 5, 2009, 10:02am UTC](https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195/1 "2009-05-05T10:02:25Z")

</div>

Hello,

I’ve just created my first plugin, is really a simple one, and it has  
only one validation, special for a spanish bank account.

As I need it in more than one RoR, I’ve decided to create as a plugin,  
but now I’m having Stack level too deep every time I save a record, no  
matter if this validation is from the same model or not, always Stack  
level too deep.

If I remove the plugin, everything works as expected.

I’m totally newbie for plugin creation, I found some examples on  
internet and tried to follow/adapt them …

Any blog, wiki, or how-to about plugin creation would be wellcome

thanks,

r.

Here are the files:

## Vendor/plugins/cc\_validator/init.rb:

# Include hook code here

ActiveRecord::Validations::ClassMethods.send :include, CcValidator  
ActiveRecord::Base.class\_eval do  
include ActiveRecord::Validations  
end

## Vendor/plugins/cc\_validator/lib/cc\_validator.rb

# CcValidator

module CcValidator

# Checks if an ActiveRecord property is a valid Spanish bank account

number.  
def validates\_cc\_of(\*attrs)  
configuration = { :message =\>  
ActiveRecord::Errors.default\_error\_messages[:invalid], :on =\> :save,  
:with =\> nil }  
configuration.update(attrs.pop) if attrs.last.is\_a?(Hash)

```
validates_each(attrs, configuration) do |record, attr_name, value|
  record.errors.add(attr_name, configuration[:message]) unless

```

cc(value) == 0  
end  
end

private

# Calculates the CC of a Spanish bank account number.

# Return value should be 0 (cc succeeded). Any other value means

faillure.

# [http://es.wikipedia.org/wiki/CÃ³digo\_Cuenta\_Cliente](http://es.wikipedia.org/wiki/C%C3%83%C2%B3digo_Cuenta_Cliente)

def cc(account)

```
...

```

…

end

end

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [May 5, 2009, 1:42pm UTC](https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195/2 "2009-05-05T13:42:36Z")

</div>

Ok, first we’ll need the exception backtrace to be sure about where  
this code is breaking, but you can start by changing your plugin a  
little bit:

## Vendor/plugins/cc\_validator/init.rb:

# Include hook code here

ActiveRecord::Base.extend CcValidator

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

On Tue, May 5, 2009 at 5:02 AM, Raimon Fs

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [May 5, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195/3 "2009-05-05T14:34:59Z")

</div>

You can try this one →   
[http://peepcode.com/products/rails-2-plugin-patterns](http://peepcode.com/products/rails-2-plugin-patterns)

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

On Tue, May 5, 2009 at 8:48 AM, Raimon Fs

---

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [May 5, 2009, 1:48pm UTC](https://www.ruby-forum.com/t/my-first-plugin-my-first-stack-level-too-deep/167195/4 "2009-05-05T13:48:32Z")

</div>

MaurÃ­cio Linhares wrote:

> Ok, first we’ll need the exception backtrace to be sure about where  
> this code is breaking, but you can start by changing your plugin a  
> little bit:
> 
> ## Vendor/plugins/cc\_validator/init.rb:
> 
> # Include hook code here
> 
> ActiveRecord::Base.extend CcValidator

Hello MaurÃ­cio,

thanks, now it works perfect!

now, where I can get more info about extending RoR with plug-ins ???

🙂

thanks …

r.
