1

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 * FROM rols

(for obvious reasons)... So, my question is: how can I tell rails to look into the "roles" table instead the "rols" table?

Thank you!

tiiin4
  • 539
  • 4
  • 7
  • 19
  • 1
    possible duplicate of [How do I override rails naming conventions?](http://stackoverflow.com/questions/1185035/how-do-i-override-rails-naming-conventions) – Lucio Jun 21 '15 at 20:12

2 Answers2

3

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:

 ActiveSupport::Inflector.inflections do |inflect|
   inflect.irregular 'rol', 'roles'
 end
ryeguy
  • 65,519
  • 58
  • 198
  • 260
2

The easiest way is to do something like:

set_table_name "roles"

in your model.

jonnii
  • 28,019
  • 8
  • 80
  • 108