Mike Andrianov
Mike Andrianov

Reputation: 3095

no implicit conversion of ActiveSupport::TimeWithZone into Integer

I want to set default time to 2 hours from now. So I wrote this peace of code:

<%= f.datetime_select :starts_at, :default => { :hour => 2.hours.from_now, :minute => 0 }, :order => [:day, :month, :year] %>

I've got an error:

no implicit conversion of ActiveSupport::TimeWithZone into Integer

Upvotes: 0

Views: 3758

Answers (2)

Tom
Tom

Reputation: 334

2.hours.from_now yields a ActiveSupport::TimeWithZone object but hour is expecting an Integer.

:hour => 2.hours.from_now.hour

I tried this and it works fine for me. Do you have a validation on your model which is causing it to fail?

Also this will not give you exactly 2 hours since you are setting the minute variable.

Upvotes: 2

Rafa Paez
Rafa Paez

Reputation: 4860

Have you tried with?

:hour => 2.hours.from_now.hour

I edited because you need the absolute hour.

Upvotes: 1

Related Questions