Struct: Difference Between Rails and Ruby/IRB

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

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.

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

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