aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/tags/month_field.rb
blob: 56bd85a90bbf4203ca2bb02cf283828f9c437ba4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module ActionView
  module Helpers
    module Tags
      class MonthField < TextField #:nodoc:
        def render
          options = @options.stringify_keys
          options["value"] = @options.fetch("value") { format_month_string(value(object)) }
          options["min"] = format_month_string(options["min"])
          options["max"] = format_month_string(options["max"])
          @options = options
          super
        end

        private

          def format_month_string(value)
            value.try(:strftime, "%Y-%m")
          end
      end
    end
  end
end