Compare date_select in rails and make sure 1st date is not later than second date -


i using date_select 2 of fields in db -

<div class="control-group">    <label class="control-label">    <%= f.label :date_one %></label> <div class="controls">    <%= f.date_select :date_one%> </div> </div>  <div class="control-group">    <label class="control-label">    <%= f.label :date_two %></label> <div class="controls">    <%= f.date_select :date_two%> </div> </div> 

now trying here is, no matter date selected date_one, date_two shouldnt before has been selected date_one. possible? how do it? possible setup validation of kind?

thanks

yes, should start on server ensure valid data going saved. add client side validations, see more information question.

well, add server side validation, in model:

validate :date_two_after_date_one  def date_two_after_date_one   errors.add :date_two, 'should after date one' if date_two < date_one end 

and client side, have use javascript that, paste form_for call.


Comments