【发布时间】:2013-05-24 05:05:38
【问题描述】:
class Country < ActiveRecord::Base
#alias_method :name, :langEN # here fails
#alias_method :name=, :langEN=
#attr_accessible :name
def name; langEN end # here works
end
第一次调用 alias_method 失败:
NameError: undefined method `langEN' for class `Country'
我的意思是当我这样做时它会失败,例如Country.first。
但在控制台中我可以成功调用Country.first.langEN,并且看到第二个调用也有效。
我错过了什么?
【问题讨论】:
标签: ruby-on-rails ruby activerecord rails-activerecord alias-method