Checking for valid date range in Rails
DRY - don't repeat yourself - basically means that you should extract repeated logic into methods.

In this case you're repeating


checking validity
creating Date instances (if they're valid, you should just create them, and then compare them; it's madness to create them for the comparison only to re-create them a few lines later)
... and for each of those, you're extracting 3 specific values from a params hash


So you could for instance do this instead:

# Returns a Date, or nil if the input isn't valid
def params_to_date(params = {})
  args = %w(year month day).map { |k| params[k] }
  Date.new(*args) if Date.valid_date?(*args)
end

# ...

def some_controller_action
  from_date = params_to_date(params[:from])
  to_date = params_to_date(params[:to])

  if from_date &amp;&amp; to_date &amp;&amp; from_date &lt; to_date
    run_report(from_date, to_date)
  else
    redirect_to :back, alert: "Please provide valid date values."
  end
end