Created
December 12, 2011 07:13
-
-
Save sj26/1465584 to your computer and use it in GitHub Desktop.
This file contains 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
= semantic_form_for @site do | |
= form.inputs do | |
= form.input :wait_duration |
This file contains 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 DurationConversion | |
extend ActiveSupport::Concern | |
included do | |
attribute_method_suffix "_duration" | |
attribute_method_suffix "_duration=" | |
end | |
# Handle *_duration for method_missing. | |
def attribute_duration(attribute_name) | |
ChronicDuration.output(send(attribute_name), :format => :long) | |
end | |
# Handle *_duration= for method_missing. | |
def attribute_duration=(attribute_name, value) | |
send(:"#{attribute_name}=", ChronicDuration.parse(value)) | |
end | |
end |
This file contains 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
gem 'chronic_duration' |
This file contains 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
class Site < ActiveRecord::Base | |
include DurationConversion | |
# t.integer :wait | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment