Skip to content

Instantly share code, notes, and snippets.

@zackfern
Created October 22, 2013 02:02
Show Gist options
  • Save zackfern/7094106 to your computer and use it in GitHub Desktop.
Save zackfern/7094106 to your computer and use it in GitHub Desktop.
Helper method for parsing the output from date_select fields.
# Public: Parse values from Rails date_select form helper.
#
# dsv - Stands for Date Select Values. Pass in whatever hash
# contains the attributes of the date_select box.
# name - Name of the Date Select. For example, if your params
# contain 'date_of_birth(2i)' then your name would be
# 'date_of_birth' (which happens to be the default)
#
# Returns a Date object.
def parse_date_select_values(dsv, name='date_of_birth')
Date.new dsv["#{name}(1i)"].to_i, dsv["#{name}(2i)"].to_i, dsv["#{name}(3i)"].to_i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment