What’s the best way to validate that the end date is not before the start date, and start date is after the end date in Rails?
I have this in my view controller:
<tr>
<td><%= f.label text="Starts:" %></td>
<td><%= f.datetime_select :start_date, :order => [:day, :month, :year]%></td>
</tr>
<tr>
<td><%= f.label text="Ends:" %></td>
<td><%= f.datetime_select :end_date,:order => [:day, :month, :year]</td>
</tr>
I want it to come up with a popup of sorts, with a meaningful message.
I would like to make a generic method that takes two parameters, start and end date, which I then can call in my viewcontroller ; fx in the code above. Or, do I need to use jQuery instead?
If you want client side validation, use jQuery.
Or in rails, to validate server side, you could create your own I guess?
Rails >= 7.0 makes this a one-liner
validates_comparison_of :end_date, greater_than_or_equal_to: :end_datePR, Rails Guides