Created
April 23, 2013 17:12
-
-
Save entrity/5445532 to your computer and use it in GitHub Desktop.
Create a #date_field helper in your Rails form builder. It is essentially #text_field, but I ended up using this a lot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView | |
module Helpers | |
class FormBuilder | |
# Make a field whose class includes 'date' and whose value can be custom-formatted | |
def date_field method, options={} | |
date = self.object.send(method).to_date | |
options[:value] = options.has_key?(:format) ? date.strftime(options[:format]) : date.to_s | |
options[:class].is_a?(String) ? options[:class] += ' date' : options[:class] = 'date' | |
rescue | |
text_field method, options | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment