Tim Cowell Tim Cowell - 8 months ago 137
Ruby Question

Chart kick Timeline using Ruby on Rails and dynamic data

I've installed Chartkick within my ROR app and I'm looking to use the timeline feature to display projects to give a simple and quick overview.

<%= @projects.each do |project|
timeline [
['project.hospital', "project.construction_start", "project.construction_end"],
] %>
<% end %>

I'm trying to get it to display all projects with the construction_start and end format be set at YYYY-MM-DD

I have no idea what to do... anything assistance would be appreciated


Your code is showing something you dont want, the loop instead the timeline, and it's showing , not one timeline but many of them .
Change your code to:

<% data = @projects.pluck(:hospital,:construction_start,:construction_end) %>
<%= timeline  data  %>  

This should only create one timeline with all the data about the hospitals of all projects you passed from the controller .

Note that this will only work on Rails 4+. If you have Rails 3 you will have to override the pluck method (it's not hard actually)