Reputation: 896
I have a do loop:
<% @currentfruit.each do |apples| %>
<%= apples.prices %>
<% end %>
It displays, as expected, a line of all apple prices ever entered in the model. I want to take this data, and plot each entry that is displayed in Highcharts, but I'm not sure how to do that.
Do I put this into an array somehow, do I run an entirely different query all together? What's the best way to accomplish this?
UPDATE:
Below Ryan's answer works great:
@currentfruit.map(&:prices).to_json
It displays an array of all the prices ever entered, just what I wanted. But when I plot them in Highcharts:
data: [ <%= @currentfruit.map(&:prices).to_json]
It only shows one data point on the chart, even though the whole array of values is displayed up above. How can I get all the values in the array to plot on the chart?
Upvotes: 0
Views: 766
Reputation: 107718
My guess is that you'll want to put this into a JSON array, which you can do with this:
@currentfruit.map(&:prices).to_json
Upvotes: 1