DateTime и DataMapper - PullRequest
       17

DateTime и DataMapper

0 голосов
/ 24 июля 2011

Задача

Я пытаюсь сэкономить +4 часа в DM. Я думаю, что DateTime является правильным, но DataMapper не работает должным образом. Есть идеи?

Контроллер

p DateTime.now
t = DateTime.now + params[:hours] / 24
p t
reward = @player.work params[:hours]
action = Action.new(:player => @player, :type => 0, :completed_at => t, :reward => reward)

модель

class Action
include DataMapper::Resource

property :id, Serial
property :type, Integer
property :completed_at, DateTime
property :reward, Integer

TYPES = {
  0 => "Work",
  1 => "Arena",
  2 => "Quest"
}

validates_with_method :type, :method => :valid_type?

def valid_type?
  if TYPES.key? self.type.to_i
    true
  else
    [false, "Invalid action type."]
  end
end

def get_type
  case TYPES[self.type]
  when "Work"
    "you're working"
  when "Arena"
    "in the arena"
  when "Quest"
    "in a quest"
  end
end

 belongs_to :player
end

1 Ответ

1 голос
/ 24 июля 2011

попробовать: DateTime.now + (params [: hours] / 24.0)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...