Question

I would like to know if there is a built-in functionality of rails time_select, that handles the valid range of my end_time.

I have start_time and end_time. end_time is not allowed to be "smaller" than start_time.

<%= f.time_select :start_time, {minute_step: 15}%>

How can I realize this?

Thank you for help.

Was it helpful?

Solution

It seems that you can't specify range via time_select. The option is to cut end_time range using javascript based on start_time value and add custom validation for reliability: http://guides.rubyonrails.org/active_record_validations.html#custom-methods.

def end_time_validity
  if end_time < start_time
    errors.add(:end_time, "can't be before start time")
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top