Created
January 25, 2013 02:05
-
-
Save carlosantoniodasilva/4631075 to your computer and use it in GitHub Desktop.
SimpleForm hour select input example.
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
# app/inputs/hour_input.rb | |
class HourInput < SimpleForm::Inputs::Base | |
def input | |
@builder.select(attribute_name, hour_options, { :selected => selected_value }, { :class => "input-medium" }) | |
end | |
private | |
# The "Selecione..." string could also be translated with something like: I18n.t("helpers.select.prompt') | |
def hour_options | |
hour = [['Selecione...', '00:00:00']] | |
(8..21).each do |h| | |
%w(00 15 30 45).each do |m| | |
hour.push ["#{h}h#{m}", "#{"%02d" % h}:#{m}:00"] | |
end | |
end | |
hour | |
end | |
def selected_value | |
value = object.send(attribute_name) | |
value && value.strftime("%H:%M:%S") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment