Rails How to avoid conflicting when naming model attributes?

tonytonyjan · 2013年05月05日 · 最后由 ailen 回复于 2013年05月09日 · 2234 次阅读

想跟各位前辈请教一下,请问有什么好方法可以避免在 generate model 时,attribute name 不会与 ActiveRecord::Base instance 既有的 method name 冲突?

例如,我们的 attribute name 不会命名成 classtoggle

@tonytonyjan 如果有冲突的话会有提示的吧

可查 rails 保留字

#1 楼 @ailen 如果一不小心用到了数据库的保留字段,这个可以不会报错的,例如 mysql 的 type,,...

#3 楼 @small_fish__ 有些保留字出错非常诡异,比如建表叫 records(似乎会导致 model 和表对应混乱),很难定位出来。

@small_fish__ 以前是在 scaffold 的时候如果遇到保留字就会报错的,自己添加的倒是没有试过

需要 登录 后方可回复, 如果你还没有账号请 注册新账号