新手问题 ActiveRecord 保留字段冲突问题?

search · July 17, 2013 · Last by greenmoon55 replied at July 17, 2013 · 3141 hits

老数据库表里有个attribute 的字段,这个不能改。而 rails 里又不能将 attribue 作为字段名。会导致

ActiveRecord::DangerousAttributeError: attribute is defined by Active Record

求解,有什么好的方法解决?前提是 attribute 这个字段名是不能改的

rails 是 4.0

alias_attribute :some_name, :attribute

#1 楼 @blacktulip 这样还会报 attribute is defined by Active Record

为什么不能改数据库字段的名字?

#3 楼 @yanhao 数据库是另一个系统的,那个系统用 c 写的,没法改

You need to Sign in before reply, if you don't have an account, please Sign up first.