我使用TypeError (can't convert Date into String)
i test& amp;获得irb
in ruby可以获得所需的值,但在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