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?
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)
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.