Thanks Nathan,
That does help some, in terms of getting it to recognize the correct method,
but I still don't quite understand how to include it. Here's what I have so
far in lib/error_message_on.rb
module ActionView
module Helpers
module ActiveRecordHelpers
module ErrorMessageOn
alias_method :original_error_message_on, :error_message_on
def error_message_on( # vars and things )
# new code....
end
end
end
end
end
What would be the correct call in environment.rb then to incorporate it?
ActionView::Helpers::ActiveRecordHelpers.send :include, ErrorMessageOn
That didn't really work though...
I don't really understand what should be including it, whether its the
ActionView or ActionView::Helpers::ActiveRecordHelpers that should be
sending the include call. I mean, I have the modules defined so that it
"should" go into ActiveRecordHelpers already, just by nesting the modules,
right? If I take out the "module ErrorMessageOn" line, so that it has one
less nest, does that mean I need to rename the file? Aye Dos Mio!
A side question directly related to all this: How does Ruby view these
modules? If you make a call to error_message_on, then its like it was
specified in the ActionView file, right? So then shouldn't I be able to just
do
module ActionView
alias_method :original_error_message_on, :error_message_on
def error_message_on
#...
end
end
or does it want:
module ActionView::Helpers::ActiveRecordHelpers
alias_method :original_error_message_on, :error_message_on
def error_message_on
#...
end
end
Food for thought. Damn, I'm hungry... mmm...Rock Bottom....mmmmmmm....
- adam
On 8/28/07, Nathan Colgate Clark <[EMAIL PROTECTED]> wrote:
>
> This might help:
> http://source.mihelac.org/2007/2/28/override-helpers-in-rails
>
> Looks like you need to toss in an alias_method or alias_method_chain after
> the method:
>
> module ActionView
> module Helpers
> module ActiveRecordHelper
> def error_message_on_with_mylook
> # ....
> end
> alias_method_chain :error_message_on, :mylook
> end
> end
> end
>
> Totally guessing there though. Good luck.
>
> Adam Grant wrote:
>
> So I wanted to overwrite 'error_message_on' method defined in
> "rails/actionpack/lib/actionview/helpers/active_record_helper.rb", but I'm
> not quite sure how to do it. These nested modules confuse me...
>
> The active_record_helper.rb contains:
>
> module ActionView
> module Helpers
> module ActiveRecordHelper
> def error_message_on
> # ....
> end
> end
> end
> end
>
>
> So if I wanted to overwrite that method, how would I do it?
>
> I essentially want to do:
>
> module ErrorMessageOn
> def error_message_on
> # new code....
> end
> end
>
> and save this file as RAILS_ROOT/lib/error_message_on.rb
>
> But how do I include this correctly?
>
> 1) ActionView::Helpers::ActiveRecordHelper.send :include, ErrorMessageOn
> 2) Maybe I need to rename it: "module
> ActionView::Helpers::ActiveRecordHelper"
> and then " ActionView.send :include,
> ActionView::Helpers::ActiveRecordHelper"
> 3) Also, I know that the /lib files all get preloaded automatically, but
> do the modules need to be named the same as the ".rb" file they are
> contained in? If that is the case, do I still need a require?
>
> Nested MODULES!! ARRGHH!!
>
> - Adam "Plea for Hizzelp" Grant
> [EMAIL PROTECTED]
>
> ------------------------------
>
> _______________________________________________
> Sdruby mailing list
> [EMAIL PROTECTED]://lists.sdruby.com/mailman/listinfo/sdruby
>
>
>
> _______________________________________________
> Sdruby mailing list
> [email protected]
> http://lists.sdruby.com/mailman/listinfo/sdruby
>
>
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby