I have some issues with a controller in my rails3 application that is called nas
My ruby app is connected to an existing DB so the table name has to stay as nas.
In my models, I have previously been able to do this:
set_table_name
But I don’t know how to do this in my controller / routes.
Right now, my routes contains this:
resources :nas
And the output is:
new_na GET /nas/new(.:format) {:action=>"new", :controller=>"nas"}
edit_na GET /nas/:id/edit(.:format) {:action=>"edit", :controller=>"nas"}
na GET /nas/:id(.:format) {:action=>"show", :controller=>"nas"}
PUT /nas/:id(.:format) {:action=>"update", :controller=>"nas"}
DELETE /nas/:id(.:format) {:action=>"destroy", :controller=>"nas"}
As you can see, rails drops the ‘s’
How can I resolve this?
Thanks
It’s pretty confusing because I have no idea what a “na” or “nas” is. From your question I have the idea that you always want to refer to it as “nas”, both plural and singular.
If that’s the case, then the answer is to put this in
config/initializers/inflections.rb:This will also make your
Nasmodel use thenastable by default, so no need forset_table_name.However note that there is no reason to use
Nasfor your controllers if you don’t want to! You can name them anything you like, as long as this is reflected inroutes.rband you use the correct model in your controller.