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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-26 14:56 UTC
Re: Missing Method defined in controllers/application.rb
On 26 Mar 2008, at 14:53, James Byrne 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) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Byrne
2008-Mar-26 15:12 UTC
Re: Missing Method defined in controllers/application.rb
Frederick Cheung 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---