def function1
@user=User.find(params[:user_id])
@participants=Participant.find_all_by_user_id(params[:user_id])
bar_1_data = @user.get_total
bar_2_data = params[:count]
color_1 = 'c53711'
color_2 = '0000ff'
min=0
max=100
puts(bar_1_data) # prints 2 on console
puts(bar_2_data) # prints 3 on console
puts (bar_1_data).is_a? Integer # prints true
puts (bar_2_data).is_a? Integer # prints false
bc=GoogleChart::BarChart.new("300x80", " ", :horizontal, false)
bc.data " ", [100], 'ffffff'
bc.data "Bar1", bar_1_data, color_1
bc.data "Bar2", bar_2_data.to_i, color_2
bc.axis :x, :range => [min,max]
bc.show_legend = true
bc.stacked = false
bc.data_encoding = :extended
@bc= bc.to_url
end
end
我得到參數錯誤「比較字符串與100失敗」int上述控制器代碼。然後,我改變了線未定義的方法`收集'爲2:Fixnum
bc.data "Bar1", bar_1_data, color_1
bc.data "Bar2", bar_2_data, color_2
到
bc.data "Bar1", bar_1_data.to_i, color_1
bc.data "Bar2", bar_2_data.to_i, color_2
這給了我undefined method collect for 2:Fixnum
在行@bc= bc.to_url
。 在控制檯上它提供了以下錯誤:
NoMethodError (undefined method `collect' for 2:Fixnum):
gchartrb (0.8) lib/google_chart/base.rb:499:in `extended_encode'
gchartrb (0.8) lib/google_chart/base.rb:461:in `encode_data'
gchartrb (0.8) lib/google_chart/bar_chart.rb:69:in `process_data'
gchartrb (0.8) lib/google_chart/bar_chart.rb:68:in `collect'
gchartrb (0.8) lib/google_chart/bar_chart.rb:68:in `process_data'
gchartrb (0.8) lib/google_chart/base.rb:440:in `add_data'
gchartrb (0.8) lib/google_chart/base.rb:305:in `prepare_params'
gchartrb (0.8) lib/google_chart/base.rb:77:in `to_url'
app/controllers/assess_controller.rb:139:in `function1'
gchartrb (0.8) lib/google_chart/bar_chart.rb:22:in `initialize'
app/controllers/assess_controller.rb:131:in `new'
app/controllers/assess_controller.rb:131:in `function1'
/Library/Ruby/Gems/1.8/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier/rack.rb:27:in `call'
/Library/Ruby/Gems/1.8/gems/hoptoad_notifier-2.4.11/lib/hoptoad_notifier/user_informer.rb:12:in `call'
Rendering rescues/layout (internal_server_error)
試圖在視圖打印bc
爲<p><img src="<%= puts (@bc) %>" ></p>
,它不打印任何東西,但是當我在控制器打印bc
它打印 #<GoogleChart::BarChart:0x103be9660>
。
我是不是正確地發送到視圖?我已經嘗試@bc=bc.to_url
和puts bc.to_url
,如http://gchartrb.rubyforge.org/。
我錯過了什麼?
你嘗試過'bc.data「Bar1」,bar_1_data.map(&:to_i),color_1'嗎? – Jan
給出'未定義的方法'映射'爲2:Fixnum' – Ava