I have a Rails 3.2.8 model that is in a namespace. I'm sure it used to be that the namespace was automatically expanded out into what the table name would look like. e.g. Module::Model would become module_model in the database.
For some reason I have a problem now that this does not happen through the rails application. The migrations, models and controllers all live in a namespace but when the model looks for a table it ignores the table prefix and complains that it cannot find the database.
Here is the example
module Magazine
def self.table_name_prefix
'magazine_'
end
end
module Magazine
class Paper < ActiveRecord::Base
#some stuff here
end
end
When I do a query on Magazine::Paper it looks for the table "paper" and not "maganzine_paper" which it should. This is causing the whole application to exibit some weird behaviour. I have also tried setting the table name manually in the model with self.table_name but this only lets the model find the right table. Routes still play games with me as when I nest something below papers for example comments then it looks for a route that does not exist.
This is what is inside the routes. Comments should go to /magazine/papers/1/comments but it looks for a route called /magazine/comments
namespace :magazine do
resources :papers do
resources :comments
end
end
What is going on?
Update:
Ok so I figured it out but not sure if I should ignore it or see whats causing it. The engine name is magazine and in the engine I create a namespace for models called magazine but this causes the problems. So rails can't have a namespace name similar to the engine name?