Modules and models

Hello!

I have a question on using modules with models.

If I do, for example, “script/generate controller Section::Users”
Rails creates /controllers/section/users_controller.rb which contains:

class Section::UsersController < ApplicationController
end

Then, using “script/generate model Section::User” Rails creates /
models/section/user.rb with:

class Section::User < ActiveRecord::Base
end

Now, if I try to do something like “scaffold :user” in the controller
and “set_table_name :users” in the model, browsing to “/section/
users/” I get the following error:

NameError in Section/users#index
uninitialized constant User

The same if I use something like “User.find(:all)” in the controller.

What’s the problem? Why can’t I use a module for models? There’s
surely something I haven’t considered…

Thanks,
Silvano


. . . Silvano S. . . .
e-mail: [email protected]
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog

Hello Silvano,

I may be oversimplifying things but why not just have:

script/generate model User

I think it can’t find Section::User because you are referencing it as
just
User. That’s not the same thing, those are two different classes.

If you did Section::User.find(:all) I’m guessing it would work?

I’m still a newbie, so someone correct me where I’m wrong.

-andy

On 11/9/05, Silvano S. [email protected] wrote:

NameError in Section/users#index


Andrew S.

Hello Andrew,

Il giorno 10/nov/05, alle ore 02:09, Andrew S. ha scritto:

If you did Section::User.find(:all) I’m guessing it would work?

Yes: now everything is working (included scaffold)!!

I’m still a newbie, so someone correct me where I’m wrong.

I’m newbie too…

-andy

Thank you,
Silvano


. . . Silvano S. . . .
e-mail: [email protected]
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog