问题
我基本上是想在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
尝试:DateTime.now+(params[:hours]/24.0(