2013-01-03 6 views
1

저는 레일스에 상당히 익숙하며 데이터베이스 테이블에서 created_at 날짜를 가져 오기 위해 lazy_high_charts에 pointStart 날짜를 설정하려고합니다. 나는 그것을 장난 봤는데Rays/Lazy_High_Charts로 정의되지 않은 메소드`year '

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 

:

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

가 여기 내 컨트롤러 # 지수입니다 : 내가 왜 날짜를 포맷하려고 다음과 같은 오류가 나는 확실하지 않다 그리고 이것은 내가 얻을 수있는 가장 가까운 곳입니다.

답변

2

귀하는 날짜를 전달해야하는 문자열을 전달하고 있습니다.

이 작업을 시도 할 수 있습니다 :

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

하하! 와우, 내가 그걸 시도하고 다른 오류가 있다는 것을 맹세 할 수는 있었지만 나는 그렇지 않다고 생각한다. ... 그 순간들 중 하나. 도와 주셔서 감사합니다! – Desmond