# Struct: Difference Between Rails and Ruby/IRB

**URL:** <https://www.ruby-forum.com/t/struct-difference-between-rails-and-ruby-irb/75536>\
**Category:** Rails\
**Created:** [November 10, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/struct-difference-between-rails-and-ruby-irb/75536 "2006-11-10T19:43:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [November 10, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/struct-difference-between-rails-and-ruby-irb/75536/1 "2006-11-10T19:43:09Z")

</div>

Hello,

I am having a problem using a Struct in one of my controllers. My  
code works fine in a standalone Ruby program and in IRB but fails in  
Rails.

Here’s the code:

Result = Struct.new :status, :detail, :url  
r = Result.new ‘OK’, ‘Top banana’, ‘[http://blah](http://blah)’

When that’s executed in one of my actions, Rails give me this:

SyntaxError (/path/to/app/config/…/app/controllers/  
store\_controller.rb:79: dynamic constant assignment  
Result = Struct.new(:status, :detail, :url)  
^):  
[rest of trace snipped]

Any guidance would be much appreciated.

Thanks and regards,  
Andy S.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [November 11, 2006, 10:40am UTC](https://www.ruby-forum.com/t/struct-difference-between-rails-and-ruby-irb/75536/2 "2006-11-11T10:40:54Z")

</div>

Try putting Result = Struct.new(:status, :detail, :url) outside your  
action and directly in the controller class, so it’s scope is  
StoreController::Result

Vish

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [November 11, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/struct-difference-between-rails-and-ruby-irb/75536/3 "2006-11-11T19:12:13Z")

</div>

> Try putting Result = Struct.new(:status, :detail, :url) outside your  
> action and directly in the controller class, so it’s scope is  
> StoreController::Result
> 
> Vish

That fixed it. I see the problem now.

Thank you very much!  
Andy
