Carl
Carl

Reputation: 1276

How do I add time from a database in Rails?

I am fairly new to rails, and attempting to add an amount of time to a datetime in the database. The time and time unit both are returned from the database.

So the data is...

start: 11/1/2015 10:45:00
duration: 75
unit: "minutes"

I want to add the 75 minutes to the start. I know I can do this if I know them already by saying start + 75.minutes, but how do I do this when both the duration and the unit are variables?

Upvotes: 1

Views: 41

Answers (1)

makhan
makhan

Reputation: 4009

Use send method:

start + duration.send(unit)

Upvotes: 1

Related Questions