Forum: Ruby on Rails where to define a struct

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.
58859dce5a47ad5731077d386634379b?d=identicon&s=25 Cagan S. (cagan327)
on 2006-06-14 11:51
Hello,

I'm trying to use the following Struct in my web app:
  UserInfo = Struct.new( "UserInfo", :first_name, :last_name, :email,
:domain_name )

I placed this in the environment.rb, thinking that it should be
initialized only once.
But when I try to access it from within my controller, I get:

undefined method `UserInfo' for #<UserController:0x243ad5c>.

so my questions are:

1) is environment.rb the correct place to define a struct? If not,
what's the alternative. Also, what's the best place to define classes
that are neither controllers nor models?
2) if  environment.rb is the proper place to define a struct,  how can I
get my controller to know what a UserInfo is?

Thanks in advance.
Cagan
Alex Wayne (Guest)
on 2006-06-14 17:46
cagan senturk wrote:
> Hello,
>
> I'm trying to use the following Struct in my web app:
>   UserInfo = Struct.new( "UserInfo", :first_name, :last_name, :email,
> :domain_name )
>
> I placed this in the environment.rb, thinking that it should be
> initialized only once.
> But when I try to access it from within my controller, I get:
>
> undefined method `UserInfo' for #<UserController:0x243ad5c>.
>
> so my questions are:
>
> 1) is environment.rb the correct place to define a struct? If not,
> what's the alternative. Also, what's the best place to define classes
> that are neither controllers nor models?
> 2) if  environment.rb is the proper place to define a struct,  how can I
> get my controller to know what a UserInfo is?
>
> Thanks in advance.
> Cagan

Doesn't your database serve as the type definition?  Ruby usually
doesn't usually require structs like this.
This topic is locked and can not be replied to.