Answer the question
In order to leave comments, you need to log in
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
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question