2013-01-03 47 views
1

我是相當新的軌道,我試圖設置lazy_high_charts中的pointStart日期從我的數據庫表中拉出created_at日期。我在嘗試格式化日期時,下面的錯誤,我不知道爲什麼:未定義的方法`年'與Rails/Lazy_High_Charts

undefined method 'year' for "Nov 13, 2012":String

這裏是我的控制器#指數:

def index 
authorize! :index, @user, :message => 'Not authorized as an administrator.' 

@date = User.pluck(:created_at).first 

@count = User.pluck(:sign_in_count) 

@h = LazyHighCharts::HighChart.new('graph') do |f| 
f.options[:title][:text] = "Number of Logins" 
f.options[:chart][:defaultSeriesType] = "area" 
f.options[:chart][:inverted] = false 
f.options[:chart][:zoomType] = 'x' 
f.options[:legend][:layout] = "horizontal" 
f.options[:legend][:borderWidth] = "0" 
f.series(:pointInterval => 1.day, :pointStart => @date.strftime("%b %d, %Y"), :name => 'Logins', :color => "#b00000", :data => @count) 
f.options[:xAxis] = { :minTickInterval => 24 * 3600 * 1000, :type => "datetime", :dateTimeLabelFormats => { day: "%b %e"}, :title => { :text => nil }, :labels => { :enabled => true } } 
    end 
end 

我已經搞亂它的而這是我能得到的最接近的。

回答

2

你正在傳遞一個字符串,你應該傳遞一個日期。

你可以試試這個:

f.series(:pointInterval => 1.day, :pointStart => @date, :name => 'Logins', :color => "#b00000", :data => @count) 
+0

哈哈!哇,我可以發誓我試過了,並得到了一個不同的錯誤,但我猜不是。 ......那些時刻之一。謝謝您的幫助! – Desmond