ruby - Model date validation in Rails -


i'm building calendar app , have problems date validations. want allow users make future events. after adding custom validator

class event < activerecord::base   belongs_to :user    validates :name, presence: true   validates :date, presence: true   validate :future_event     private    def future_event     errors.add(:date, "can't in past!") if date.parse(date) < time.now   end end 

that's params debug

event: !ruby/hash:actioncontroller::parameters   name: new   date: 08/17/2015 commit: add controller: events action: create 

and error: no implicit conversion of nil string . what's mistake?

date.parse() expects string shown here. if saved :date in approprieate format should able do

date < time.now 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -