title: Using structs in Ruby on Rails gives dynamic constant assignment (SyntaxError)
body: <p>In my controller I have the following simplified code:</p>
  
  <pre><code>def index
    @dashboard_items = []
    DashItem = Struct.new(:name, :amount, :moderated)  # Error is here
  
    [:page, :post].each do |c|
      obj = c.to_s.capitalize.constantize
      @dashboard_items &lt;&lt; DashItem.new(c.to_s, obj.count, obj.count_moderated)
    end
  end
  </code></pre>
  
  <p>But Ruby gives the following error: </p>
  
  <blockquote>
    <p>dynamic constant assignment (SyntaxError)</p>
  </blockquote>
  
  <p>on the line marked above.</p>
  
  <p>Which, AFAIK, means that the constant <code>DashItem</code> is already defined. Is this correct? And what to do about it?</p>