# Missing Method defined in controllers/application.rb

**URL:** <https://www.ruby-forum.com/t/missing-method-defined-in-controllers-application-rb/132994>\
**Category:** Rails\
**Created:** [March 26, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/missing-method-defined-in-controllers-application-rb/132994 "2008-03-26T15:53:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 26, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/missing-method-defined-in-controllers-application-rb/132994/1 "2008-03-26T15:53:21Z")

</div>

I have this in my controllers/application.rb:

class ApplicationController \< ActionController::Base  
…

def datebalk!  
# set regexp for datebalks generated attributes  
c = /.\*\_\_dteblk/  
# Remove datebalks generated attributes from params hash  
delete\_if { |k, v| c =~ k.to\_s }  
end

…  
end

When I call this from client\_controllers.rb in this fashion:

```
# need this to strip out observer attributes for datebalks plugin
@client = @entity.build_client(params[:client].datebalk!)

```

I get this exception:

undefined method `datebalk!’ for #HashWithIndifferentAccess:0xb6c9276c

RAILS\_ROOT: /home/byrnejb/Software/Development/Projects/proforma  
Application Trace | Framework Trace | Full Trace

app/controllers/clients\_controller.rb:49:in `create’

I evidently misunderstand something fundamental about the role of  
application.rb with respect to methods. Where should method datebalk!  
be defined or what have I done wrong?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 26, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/missing-method-defined-in-controllers-application-rb/132994/2 "2008-03-26T15:57:13Z")

</div>

On 26 Mar 2008, at 14:53, James B. wrote:

> I evidently misunderstand something fundamental about the role of  
> application.rb with respect to methods. Where should method datebalk!  
> be defined or what have I done wrong?

You’ve defined a method on ApplicationController (and hence it’s  
subclasses) but you’re calling it on an instance of Hash.

Perhaps the quickest way out would to make that method take as an  
argument the hash to work on.

Fred

(PS: the .\* in your regexp does nothing, and certainly doesn’t  
guarentee that the match is found at the end of the string)

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [March 26, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/missing-method-defined-in-controllers-application-rb/132994/3 "2008-03-26T16:12:50Z")

</div>

Frederick C. wrote:

> You’ve defined a method on ApplicationController (and hence it’s  
> subclasses) but you’re calling it on an instance of Hash.
> 
> Perhaps the quickest way out would to make that method take as an  
> argument the hash to work on.
> 
> Fred

This is the second time that I have made this type of error. Perhaps  
eventually I will learn to understand what I am reading.

> (PS: the .\* in your regexp does nothing, and certainly doesn’t  
> guarentee that the match is found at the end of the string)

I take your point. This is what I ended up with in  
config/initializers/hash\_addins.rb

class Hash  
def datebalk!  
# set regexp for datebalks generated attributes  
c = /\_\_dteblk\Z/  
# Remove datebalks generated attributes from params hash  
delete\_if { |k, v| c =~ k.to\_s }  
end  
end

And this works just fine. Thank you very much for the pointers.
