Forum: Ruby on Rails Modules and models

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dc64befa87f79e074d55f83bcf9daa49?d=identicon&s=25 silvano.stralla (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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 Stralla . . .
e-mail: silvano.stralla@sistrall.it
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog
18d8b0c948dd7b3d39c9667cfd4e817c?d=identicon&s=25 stonelists (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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 Stralla <silvano.stralla@sistrall.it> wrote:
>
> NameError in Section/users#index
>
>
--
Andrew Stone
Dc64befa87f79e074d55f83bcf9daa49?d=identicon&s=25 silvano.stralla (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hello Andrew,

Il giorno 10/nov/05, alle ore 02:09, Andrew Stone 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 Stralla . . .
e-mail: silvano.stralla@sistrall.it
site: http://www.sistrall.it
flog: http://www.sistrall.it/flog
This topic is locked and can not be replied to.