Where to define a struct


#1

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


#2

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.