Bry*_*ard 13 model ruby-on-rails naming-conventions
在我正在构建的应用程序中,我使用acts_as_tree关联将XML文件存储在我的数据库中.我想命名这个类,XMLElement但由于大写是非标准的,因此抛出了轨道.它正在寻找XMLElement文件名xml_element.rb.我尝试更改文件名以x_m_l_element.rb试图欺骗它认为"XML"实际上是两个单词,但这也不起作用.我应该把它吸干并使用名称XmlElement而不是更理想的名称XMLElement,还是有更好的解决方法?
Mik*_*ike 33
添加以下内容config/initializers/inflections.rb.
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'XML'
end
Run Code Online (Sandbox Code Playgroud)
现在运行$ rails g model XMLElement…将创建一个XMLElement在命名文件xml_element.rb和关联表中命名的类xml_elements.