aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorLiborio Cannici <lic@crd.dk>2011-09-15 00:35:53 +0200
committerJeremy Kemper <jeremy@bitsweat.net>2011-10-08 18:02:15 -0700
commit114218e4da9a2adf7b6ef4a27d2fa47e15881cf1 (patch)
treee6040f8874b89e2eee894f1cb96bcb611ff633d4 /actionpack/lib
parentf655895e87c8e013caac649986510eff4d3b03d9 (diff)
downloadrails-114218e4da9a2adf7b6ef4a27d2fa47e15881cf1.tar.gz
rails-114218e4da9a2adf7b6ef4a27d2fa47e15881cf1.tar.bz2
rails-114218e4da9a2adf7b6ef4a27d2fa47e15881cf1.zip
Fixes an issue when creating a date select with too many options.
Inspired by dlt https://github.com/dlt/rails/commit/9e615634745dc81598e7b880d52411338d3a7a93 Closes #239. Conflicts: actionpack/CHANGELOG
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index e850c258ce..4deb87180c 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -765,11 +765,16 @@ module ActionView
if @options[:use_hidden] || @options[:discard_year]
build_hidden(:year, val)
else
- options = {}
- options[:start] = @options[:start_year] || middle_year - 5
- options[:end] = @options[:end_year] || middle_year + 5
- options[:step] = options[:start] < options[:end] ? 1 : -1
- options[:leading_zeros] = false
+ options = {}
+ options[:start] = @options[:start_year] || middle_year - 5
+ options[:end] = @options[:end_year] || middle_year + 5
+ options[:step] = options[:start] < options[:end] ? 1 : -1
+ options[:leading_zeros] = false
+ options[:max_years_allowed] = @options[:max_years_allowed] || 1000
+
+ if (options[:end] - options[:start]).abs > options[:max_years_allowed]
+ raise ArgumentError, "There're too many years options to be built. Are you sure you haven't mistyped something? You can provide the :max_years_allowed parameter"
+ end
build_options_and_select(:year, val, options)
end