I have a simple problem regarding a loop in a Rails controller.
Here's the original sample code, the purpose of which is to specify the data to be used in an open flash chart (pie chart).
#controller
data_1 = [
OFC2::PieValue.new(:value => 20, :label => 'GroupA', :font_size => 15),
OFC2::PieValue.new(:value => 30, :label => 'GroupB', :font_size => 15)
]
I need to do this:
data_1 = [
@groups.each do |group|
OFC2::PieValue.new(:value => group.value, :label => group.name, :font_size => 15),
end
]
Two questions:
- The comma at the end of that line poses a problem. The last entry cannot have a comma.
Even when I try to get this simple loop working by temporarily bypassing the comma (such as adding another record after the end without a comma), I am getting errors:
unexpected ',', expecting kEND (for OFC2 line)
unexpected ']', expecting kEND (last line of above code)
unexpected kEND, expecting ']' (end of controller)
This is bugging me because it should be a simple loop. What's going on?
Maybe try going a different route.
Does this make sense?