title: Rails form: auto-set a future date based on date set
body: <p>My Rails form asks users to input a start date for an event, and then an end date for the same event. I am setting the default start date to Time.now</p>
  
  <p>Is it possible to that the user can only ever choose an end date that occurs ON or AFTER the start date? (so when they change the start date, the end date auto-updates)?</p>
  
  <p>My Events controller: </p>
  
  <pre><code>def new
      @event = Event.new(params[:event])
  
      # set date_start field to be today's date
      @event.date_start = Time.now
      @event.date_end = @event.date_start     
  end
  </code></pre>
  
  <p>Form (shortened...)</p>
  
  <pre><code>&lt;%= form_for(@event) do |f| %&gt;  
      &lt;%= f.label :date_start, "Start date" %&gt;
      &lt;%= f.date_select(:date_start, :prompt =&gt; { :day =&gt; 'Day', :month =&gt; 'Month', :year =&gt; 'Year' }) %&gt;             
  
      &lt;%= f.label :time_start, "Start time" %&gt;
      &lt;%= f.time_select :time_start, { :minute_step =&gt; 5 } %&gt;                             
  
  
      &lt;%= f.label :date_end, "End date" %&gt;
      &lt;%= f.date_select(:date_end, :prompt =&gt; { :day =&gt; 'Day', :month =&gt; 'Month', :year =&gt; 'Year' }) %&gt;   
  &lt;% end %&gt;
  </code></pre>