class Country < ActiveRecord::Base
#alias_method :name, :langEN # here fails
#alias_method :name=, :langEN=
#attr_accessible :name
def name; langEN end # here works
end
Run Code Online (Sandbox Code Playgroud)
在第一次呼叫alias_method
失败时:
NameError: undefined method `langEN' for class `Country'
Run Code Online (Sandbox Code Playgroud)
我的意思是,当我这样做时,它失败了Country.first
.
但是在控制台中我可以Country.first.langEN
成功调用,并看到第二个调用也可以.
我错过了什么?
ruby activerecord ruby-on-rails alias-method rails-activerecord