Namespaced Scaffolds and AR

Just wondering about the decisions on name space handling. Wondering
if this is a bug or by design and if maybe it should be changed. (I'd
be glad to bugfix).

In the case I ran: $ rails g scaffold Ecom::Cart

the migration would create a table named ecom_carts. The model and
Controller would be placed in the appropriate folders ecom/cart.rb.
but when you run the tests ActiveRecord clearly errors searching for
table my_database.carts. So the pattern for the scaffold seems to
handle the name spacing appropriately everywhere but AR doesn't follow
the pattern when searching for the table.

Just wondering if there was a reason behind that or if I should branch
and try and bug fix?

Cheers,
Brian

Works fine for me thanx to ecom.rb

module Ecom

def self.table_name_prefix

‘ecom_’

end

end

make sure that you have

class Ecom::Cart < ActiveRecord::Base

end

instead of

module Ecom

class Cart < ActiveRecord::Base

end

end

in your ecom/cart.rb

Robert Pankowecki

http://robert.pankowecki.pl

Hey Robert,

This is a good solution to the generated code but my concern is why is
this solution needed at all. This file isn't generated via the
scaffold which means without knowledge of it after you generate the
scaffold the code is broken by default
Edit: I was wrong. Rails 3 does generate the ecom.rb file accordingly
with the scaffold. Rails 2.3.10 does not.

Even so, if the scaffold knows how to generate the proper table name
from Ecom::Cart. Why does active record need us to explicitly define a
table_name_prefix. Shouldn't it have the same ability to work out that
the Ecom::Cart table is ecom_carts? and If not I'm really just
wondering the design reasoning behind deciding to go with the ecom.rb
method. I'm mainly interested in the process of decision making I
think.

Cheers,
Brian

I think it is done this way to easily overwrite
table_name_prefix for all tables of namespaced models. And when it comes to decision making process I know nothing about it so I cannot help you with that question.

Robert