मेरी नियंत्रक में मैं निम्नलिखित सरल कोड है:रूबी में ऑन रेल्स structs का उपयोग गतिशील लगातार काम (सिंटैक्स) देता है
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 << DashItem.new(c.to_s, obj.count, obj.count_moderated)
end
end
लेकिन रूबी निम्न त्रुटि देता है: लाइन पर
dynamic constant assignment (SyntaxError)
ऊपर चिह्नित
जो, AFAIK का अर्थ है कि निरंतर DashItem
पहले ही परिभाषित किया गया है। क्या ये सही है? और इसके बारे में क्या करना है?
ओर ध्यान दें: खाली सरणी + प्रत्येक + संलग्न = नक्शा – tokland
[गतिशील लगातार काम] (http://stackoverflow.com/questions/6712298/dynamic-constant-assignment) –