Forum: Ruby on Rails alias_method interferes ApplicationHelper

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Arie Kusuma A. (Guest)
on 2006-03-12 18:22
(Received via mailing list)
Hello,
I'm using Ruby 1.8.4 (darwinport), rails-1.0.0 (gem) , Powerbook / Mac
OS X 10.4.5 , Webrick.
How come Rails always raises NoMethodError for my helper (must_fill and
rp or number_to_currency_rp) in application_helper.rb ?
I doubt that alias_method is the culprit, but if i give #
comment then there will be no errors at all ... :/
what am i doing wrong? is it a bug or stupid me? Thx

------------------
This is my helper:
------------------
module ApplicationHelper
   alias_method :rp, :number_to_currency_rp

	# Rp 1.907.000,00 instead of $1,907,000.00
	def number_to_currency_rp(dolar)
	  number_to_currency(dolar, {:unit => "Rp ", :separator => ",",
:delimiter => "."})
	end

   def must_fill(x)
     '<span style="color:red;">' + x + '</span>'
   end
end

--------------------
 From ri -f bs alias:
---------------------------------------------------- Module#alias_method
      alias_method(new_name, old_name)   => self
------------------------------------------------------------------------
      Makes _new_name_ a new copy of the method _old_name_. This can be
      used to retain access to methods that are overridden.

         module Mod
           alias_method :orig_exit, :exit
           def exit(code=0)
             puts "Exiting with code #{code}"
             orig_exit(code)
           end
         end
         include Mod
         exit(99)

      _produces:_

         Exiting with code 99


--
sig "kind regards" :name => " Arie Kusuma A. ", :callme => " Arie ",
:ym => " riyari3 ", :email => " removed_email_address@domain.invalid ".chop!,
:dotmac => " ariekusumaatmaja ", :blog => "
http://ariekusumaatmaja.wordpress.com ".chop, :pasrubylangage => %q#
Learn & Enjoy English Together: http://indoforums.com/englishklab #

Besoin d'apprendre beaucoup plus.. deutsch, dutch, italie..
wind lang (donc etre solomon)
Kent S. (Guest)
on 2006-03-12 18:53
(Received via mailing list)
You should first define a method and then alias it:

module ApplicationHelper
       # Rp 1.907.000,00 instead of $1,907,000.00
       def number_to_currency_rp(dolar)
         number_to_currency(dolar, {:unit => "Rp ", :separator => ",",
:delimiter => "."})
       end
       alias_method :rp, :number_to_currency_rp

end

--
Kent
This topic is locked and can not be replied to.