# Where to define a struct

**URL:** <https://www.ruby-forum.com/t/where-to-define-a-struct/63340>\
**Category:** Rails\
**Created:** [June 14, 2006, 11:51am UTC](https://www.ruby-forum.com/t/where-to-define-a-struct/63340 "2006-06-14T11:51:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cagan327](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cagan327](https://www.ruby-forum.com/u/cagan327)\
**Post date:** [June 14, 2006, 11:51am UTC](https://www.ruby-forum.com/t/where-to-define-a-struct/63340/1 "2006-06-14T11:51:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cagan327](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dbc845/32.png) [@cagan327](https://www.ruby-forum.com/u/cagan327)\
**Post date:** [June 14, 2006, 12:38pm UTC](https://www.ruby-forum.com/t/where-to-define-a-struct/63340/2 "2006-06-14T12:38:22Z")

</div>

On 6/14/06, cagan senturk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
