I am trying to validate a model using :presence => true on certain fields, but the model is being returned as valid even if these fields are nil. Here are the validations of my Replay model:
validate :match_id, :presence => true
validate :replay_url, :presence => true
validate :uploader_id, :presence => true
If I open up the console and type the following, you can see what I mean:
1.9.3p0 :001 > r = Replay.new
=> #<Replay id: nil, match_id: nil, replay_url: nil, created_at: nil, updated_at: nil, uploader_id: nil>
1.9.3p0 :002 > r.valid?
=> true
Does anyone know why this is?
You should use method validates instead of validate.