Hello, I have a job model which has many attributes. I would like to use graphics to display the sum of some of these attributes. For that, I am using the following code in the javascript portion of the view which produces the graph:
<% for job in @daily_jobs %>
['<%= job.day %>',<%= job.walltime %>],
<% end %>
This returns this:
['2010-07-25', 1234],
['2010-07-26', 3456],
['2010-07-27', 1234],
Which is working fine. However, I do not only want to create graphs of the atribute "walltime", but for many other atributes: memory, cpu, etc...So i would have to create functions such as:
<% for job in @daily_jobs %>
['<%= job.day %>',<%= job.cpu %>],
<% end %>
AND
<% for job in @daily_jobs %>
['<%= job.day %>',<%= job.memory %>],
<% end %>
to create the other graphs, but this is not DRY at all, I would like a single function in which I could pass the atribute as an argument. But I do not know how to do this.
for example:
function(cpu)
would return
['<%= job.day %>',<%= job.cpu %>],
and
function(walltime)
would return
['<%= job.day %>',<%= job.walltime %>],