Modules and models


#1

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: removed_email_address@domain.invalid
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog


#2

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. removed_email_address@domain.invalid wrote:

NameError in Section/users#index


Andrew S.


#3

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: removed_email_address@domain.invalid
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog