Rails 2.3.9 复数模型名称问题
我正在开发一个简单的选择。问题是我的代码需要使用西班牙语,所以 我必须使用 Rol (复数保持不变:角色),而不是使用角色。
所以,我的模型名称是:Rol,我的控制器名称是:Roles,在我的数据库中是:Roles
<% roles = Rol.all %>
<%= collection_select(:usuario, :rol_id, roles, :id, :nombre, {:prompt => true}) %>
但是,当我运行该代码时,我得到:
ActiveRecord::JDBCError:表 “turaser2.rols”不存在:选择 *来自
角色
(出于明显的原因)...所以,我的问题是:我如何告诉rails查看“roles”表而不是“rols”表?
谢谢你!
I'm developing a simple select. The thing is my code needs to be in spanish, so
instead of using Role I have to use Rol (the plurar remains the same: Roles).
So, my model name is: Rol and my Controller name: Roles and in my DB: Roles
<% roles = Rol.all %>
<%= collection_select(:usuario, :rol_id, roles, :id, :nombre, {:prompt => true}) %>
However, when I run that code I get:
ActiveRecord::JDBCError: Table
'turaser2.rols' doesn't exist: SELECT
* FROMrols
(for obvious reasons)... So, my question is: how can I tell rails to look into the "roles" table instead the "rols" table?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
做到这一点的最佳方法是向变形器添加一个新条目。如果您仅使用
set_table_name
设置表名称,那么在您可能想要使用它的其他地方,复数形式仍然会失败。转到 config/initializers/inflections.rb 并添加:
The best way to do this is to add a new entry to the inflector. If you only set the table name with
set_table_name
, the pluralization will still fail anywhere else you may want to use it.Go to
config/initializers/inflections.rb
and add:执行以下操作:
最简单的方法是在您的模型中
The easiest way is to do something like:
in your model.