Skip to content

Commit

Permalink
cannot use POSITION in actionview to map value key
Browse files Browse the repository at this point in the history
  • Loading branch information
adzap committed May 15, 2018
1 parent 90501a8 commit 84b1885
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/validates_timeliness/extensions/date_time_select.rb
Expand Up @@ -7,6 +7,10 @@ module TimelinessDateTimeSelect
# It's a minor usability improvement which is rarely an issue for the user.
attr_accessor :object_name, :method_name, :template_object, :options, :html_options

POSITION = {

This comment has been minimized.

Copy link
@AquisTech

AquisTech May 16, 2018

Contributor

@adzap I would like to know more about this change. I prefer using already defined constants from framework instead of redefining new. So that if any changes are done to the constant our code will adapt to the change.
There must be some reason you did this change. Can you tell me the purpose?

This comment has been minimized.

Copy link
@adzap

adzap May 16, 2018

Author Owner

The issue was it was failing. The key names of minute and second in that position hash where then attempted to look up the value in the DateTimeSelector class to get the object value, but that class uses sec and min as the lookup key
or method name https://github.com/rails/rails/blob/aea6423f013ca48f7704c70deadf2cd6ac7d70a1/actionview/lib/action_view/helpers/date_helper.rb#L849

This comment has been minimized.

Copy link
@AquisTech

AquisTech May 17, 2018

Contributor

Ok got it. Such a minute difference but may lead to an error.
Thanks for the explanation.

:year => 1, :month => 2, :day => 3, :hour => 4, :min => 5, :sec => 6
}.freeze

def initialize(object_name, method_name, template_object, options, html_options)
@object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
@template_object, @options, @html_options = template_object, options, html_options
Expand All @@ -21,7 +25,7 @@ def value(object)
values = {}
pairs.each_pair do |key, value|
position = key[/\((\d+)\w+\)/, 1]
values[::ActionView::Helpers::DateTimeSelector::POSITION.key(position.to_i)] = value.to_i
values[POSITION.key(position.to_i)] = value.to_i
end

values
Expand Down

0 comments on commit 84b1885

Please sign in to comment.