0
我有一个Rails应用程序与旧数据库对话,其中,所有列均为大写,例如NAME
,TYPE
,CREATED_AT
。提供将这些列重命名为小写不是一种选择。如何遍历所有属性和alias_attribute?
我知道可以使用 alias_attribute, :new_name, :old_name
创建别名。
但是,有没有办法循环所有的列和别名的属性小写?像下面这样:
class Apple < ActiveRecord::Base
Apple.attribtues.each do |att|
alias_attribute :att.down_case, :att
end
end
我的答案是否奏效?让我知道你是否仍然需要帮助。谢谢! – Powers