Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created January 25, 2013 02:05
Show Gist options
  • Save carlosantoniodasilva/4631075 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/4631075 to your computer and use it in GitHub Desktop.
SimpleForm hour select input example.
# 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