开发者

A simple controller loop (including open flash chart)

I have a simple problem regarding a loop in a Rails control开发者_Python百科ler.

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:

  1. The comma at the end of that line poses a problem. The last entry cannot have a comma.
  2. 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.

data_1 = Array.new

@groups.each do |g|
  data_1 << OFC2::PieValue.new(:value => g.value,  :label => g.name, :font_size => 15)
end

Does this make sense?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜