Rails保留类名

我尝试创建一个名为“class级”的模型(如同一个gradleclass的学生),并遇到各种各样的问题。 在Rails中要避免哪些其他单词或类名?

我找到的一些链接:
http://juicebar.wordpress.com/2007/05/30/reserved-words-in-rails/
http://railsforum.com/viewtopic.php?id=22242

此页面有一长串不使用的单词:

https://reservedwords.herokuapp.com/words

因为’class’通常作为metaprogamming的名字出现,我认为接受的ruby替代是’klass’。 这显然与您的gradleclass级情况不同,但可能仍然有用。

你在那里得到了大部分。 显然,您还需要避免使用Ruby关键字:

alias and BEGIN begin break case class def defined do else elsif END end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield 

(来自http://www.zenspider.com/Languages/Ruby/QuickRef.html#4 )。

另外,不要将模型命名为Transaction (但生成器会对此进行警告!)。

Class是一个内置的ruby类。 它是什么类的实例。

 class Foo end puts Foo.class # => Class 

覆盖会破坏Ruby中的整个对象结构。