Tag: alias method

为什么alias_method在Rails模型中失败

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 ,并看到第二个调用也可以。 我错过了什么?