1

我对 Rails 很陌生,我正在尝试在lazy_high_charts 中设置 pointStart 日期,以从我的数据库表中提取 created_at 日期。尝试格式化日期时出现以下错误,但我不确定原因:

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

这是我的控制器#index:

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

我已经搞砸了一段时间,这是我能得到的最接近的。

4

1 回答 1

2

您正在传递一个字符串,您应该在其中传递一个日期。

你可以试试这个:

f.series(:pointInterval => 1.day, :pointStart => @date, :name => 'Logins', :color => "#b00000", :data => @count)
于 2013-01-03T22:48:16.287 回答