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 struct definition in 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
Mathias Wittlock (Guest)
on 2006-06-14 12:38
(Received via mailing list)
On 6/14/06, cagan senturk <cs327@teknolabs.com> wrote:
> 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?

I'm not fully awake yet, but I think you may want to place it in your
application.rb instead, or in a separate module/helper and make sure
you include it.

HTH
Mathias.
This topic is locked and can not be replied to.