私TypeError (can't convert Date into String)
はRubyに入り、irb
i testを使用して目的の値を取得できますが、redmineのグラフプラグイン内で上記のエラーが発生します。
Ruby のバージョンは 1.9.3p0 ですが、次のエラー ログが表示されます。
TypeError (can't convert Date into String):
plugins/redmine_graphs/app/controllers/graphs_controller.rb:130:in `parse'
plugins/redmine_graphs/app/controllers/graphs_controller.rb:130:in `block in issue_growth_graph'
plugins/redmine_graphs/app/controllers/graphs_controller.rb:126:in `each'
plugins/redmine_graphs/app/controllers/graphs_controller.rb:126:in `issue_growth_graph'
vendor/gems/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal
/implicit_render.rb:4:in `send_action'
別の質問として、Ruby のバージョンは 1.9.3p0 ですが、ログでは 1.91 になっています。なぜこのようなことが起こるのでしょうか?
redmine のグラフ プラグインの次のコードは、これを引き起こします。
# Displays projects by total issues over time
def issue_growth_graph
# Initialize the graph
graph = SVG::Graph::TimeSeries.new({
:area_fill => true,
:height => 300,
:min_y_value => 0,
:no_css => true,
:show_x_guidelines => true,
:scale_x_integers => true,
:scale_y_integers => true,
:show_data_points => false,
:show_data_values => false,
:stagger_x_labels => true,
:style_sheet => "/plugin_assets/redmine-graphs-plugin/stylesheets/issue_growth.css",
:width => 720,
:x_label_format => "%Y-%m-%d"
})
# Get the top visible projects by issue count
sql = "SELECT project_id, COUNT(*) as issue_count"
sql << " FROM issues"
sql << " LEFT JOIN #{Project.table_name} ON #{Issue.table_name}.project_id = #{Project.table_name}.id"
sql << " WHERE (%s)" % Project.allowed_to_condition(User.current, :view_issues)
unless @project.nil?
sql << " AND (project_id = #{@project.id}"
sql << " OR project_id IN (%s)" % @project.descendants.active.visible.collect { |p| p.id }.join(',') unless @project.descendants.active.visible.empty?
sql << " )"
end
sql << " GROUP BY project_id"
sql << " ORDER BY issue_count DESC"
sql << " LIMIT 6"
top_projects = ActiveRecord::Base.connection.select_all(sql).collect { |p| p["project_id"] }
# Get the issues created per project, per day
sql = "SELECT project_id, date(#{Issue.table_name}.created_on) as date, COUNT(*) as issue_count"
sql << " FROM #{Issue.table_name}"
sql << " WHERE project_id IN (%s)" % top_projects.compact.join(',')
sql << " GROUP BY project_id, date"
issue_counts = ActiveRecord::Base.connection.select_all(sql).group_by { |c| c["project_id"] }
# Generate the created_on lines
top_projects.each do |project_id, total_count|
counts = issue_counts[project_id].sort { |a,b| a["date"]<=>b["date"] }
created_count = 0
created_on_line = Hash.new
#the place of error is following error
created_on_line[(Date.parse(counts.first["date"])-1).to_s] = 0
counts.each { |count| created_count += count["issue_count"].to_i; created_on_line[count["date"]] = created_count }
created_on_line[Date.today.to_s] = created_count
graph.add_data({
:data => created_on_line.sort.flatten,
:title => Project.find(project_id).to_s
})
end
# Compile the graph
headers["Content-Type"] = "image/svg+xml"
send_data(graph.burn, :type => "image/svg+xml", :disposition => "inline")
end