我实际上是想从现在开始在DM中节省+4小时。我认为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
答案 0 :(得分:1)
尝试: DateTime.now +(params [:hours] / 24.0)