M
M
Max2015-12-06 22:27:59
Ruby on Rails
Max, 2015-12-06 22:27:59

How to save data from model to database (rails)?

Hello, can you please tell me if the data that I calculate in the model can be saved in the database?
I display a table from the database, and along the way in one of the columns I display the data that I consider in the model. The problem is that based on this data, I need to build a chart. The diagram is quietly built on the basis of data from the database, but does not want to take it from the model. How to solve such a problem?

def current_money
    doctor_hour_price.to_f*users.where("enter_date >= ?", 7.days.ago).count
  end

It's not so important what the function does, it's important how to write what it does in the database) View
Model
e56d7faa9a274d4297f44a9851a20120.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2015-12-07
@maxprof

before_save :set_current_money

def set_current_money
    self.current_money ||= self.doctor_hour_price.to_f*self.users.where("enter_date >= ?", 7.days.ago).count
 end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question