Arie Kusuma Atmaja
2006-Mar-12 16:22 UTC
[Rails] alias_method interferes ApplicationHelper
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 Atmaja ", :callme => " Arie ", :ym => " riyari3 ", :email => " ariekusumaatmaja@gmail.com ".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)
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 On 3/12/06, Arie Kusuma Atmaja <ariekusumaatmaja@gmail.com> wrote:> > 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 Atmaja ", :callme => " Arie ", > :ym => " riyari3 ", :email => " ariekusumaatmaja@gmail.com ".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) > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060312/0b48d536/attachment.html