D
D
Damir Nurgaliev2015-05-28 11:10:15
Ruby on Rails
Damir Nurgaliev, 2015-05-28 11:10:15

How to add time to datetime ruby?

params[:event][:start_time] =params [:event][:start_time] + 1.day
        params[:event][:end_time] = params[:event][:start_time] + 1.day

Controller for events, where I first receive data from forms, and then I want to add 1 day to them, BUT:
the error comes out like this
no implicit conversion of Symbol into Integer
. I understand that the data in params is stored as a string, but I don’t know how to fix this code

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kkrieger, 2015-05-28
@kkrieger

1318996912 if time passes in this form, then do this
if in a different format, here is the dock by the method apidock.com/ruby/DateTime/strptime/class

T
thepry, 2015-05-28
@thepry

If you want to add dates, then get the Datetime from a string.
But from the error, it seems that your params[:event] returns not a hash, but an array, or a string and ruby ​​tries to convert :start_time to an integer to get the element by index.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question