У меня есть этот метод в моей модели:Rail TimeWithZone против Дата
def date_ranges
reservations = Reservation.where(["transport_id =?", transport_id])
reservations = reservations.where(['id <> ?', id]) if !id.nil?
reservations.map { |e| e.reservation_start..e.reservation_end }
end
Это работает просто отлично (благодаря некоторой помощи от StackOverflow).
Мой reservation_start
и reservation_end
столбец date
тип. Вот моя миграция:
class CreateReservations < ActiveRecord::Migration
def change
create_table :reservations do |t|
t.references :user, index: true
t.references :transport, index: true
t.date :reservation_start
t.date :reservation_end
t.timestamps
end
end
end
Если я пытаюсь запустить этот метод после перехода от типа date
колонки для datetime
типа я получаю сообщение об ошибке:
can't iterate from ActiveSupport::TimeWithZone
Это не будет работать, даже если я изменить код в моем методе к:
reservations.map do |e|
e.reservation_start.to_datetime..e.reservation_end.to_datetime
end
Какие версии Ruby/Rails вы используете? – gmile
Ruby 2.1.4 и Rails 4.1.5 –