2011-07-24 9 views
0

問題

私は本質的にDMから+4時間を節約しようとしています。私はDateTimeは正しいと思うが、DataMapperは正しく動作しない。何か案は?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

はあなたが少し明確にし、あなたなしで問題を定式化できドメイン固有のもの? – yawniek

答えて

1

試してみてください。 DateTime.now +(のparams [:時間]/24.0)

+0

私はRationalを使用しました(params [:hours]、24)ありがとう! :) – user766987