M
M
Max2015-12-05 19:06:09
Ruby on Rails
Max, 2015-12-05 19:06:09

How to build a graph in Ruby on Rails (does not display data from one column)?

Hello, I'm trying to plot with the Morris gem, but it doesn't see the value of one of the columns.
There is a table, if you take other data that is in the database, then the graph works correctly. But in my table, in one of the columns, data is displayed that is not stored in the database, but is calculated in the model.
Here is the graph plotting

Morris.Bar({
      element: 'doc_diagram',
      data: $('#doc_diagram').data('doctor'),
      xkey: 'doctor_first_name',
      ykeys: ['current_money'],
      labels: ['Series A']
    });

Here is his output
%= content_tag :div, "", id: "doc_diagram", data: {doctor: 
    @doctor} %>

Table output
<% @doctor.each do |doc| %>
      <tr>
        <td><%= doc.doctor_first_name %></td>
        <td><%= doc.doctor_second_name %></td>
        <td><%= doc.current_money %></td>
        <td><%= link_to 'Переглянути', doc %></td>
      </tr>
    <% end %>
  </tbody>

In this table, the value of current_money is of interest. I know that I called it unsuccessfully, but this does not change the essence yet. This value displays how much the doctor earned in the last week. Here is the formula
def current_money
    doctor_hour_price.to_f*users.where("enter_date >= ?", 7.days.ago).count
  end

In this formula, I multiply the doctor's salary per hour by the number of patients in the last 7 days.
The questions are: why does the graph not see this value if it is not saved in the database? How to save it in the database if I created the migration (does not send data to the database)? Or how to get around this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question