aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-06-30 22:15:12 +0300
committerMichael Koziarski <michael@koziarski.com>2008-07-03 19:26:56 +0300
commit5dd10d60bbde906449882e39278be76f1f445a41 (patch)
treed48728e719fabd0dab79011d68af65a3153c00c1 /actionpack
parentdf36a6f7598a7e963fb3d79fb48fd1c073045a43 (diff)
downloadrails-5dd10d60bbde906449882e39278be76f1f445a41.tar.gz
rails-5dd10d60bbde906449882e39278be76f1f445a41.tar.bz2
rails-5dd10d60bbde906449882e39278be76f1f445a41.zip
Remove nested ternary operators from select_year in favour of conditionals.
Diffstat (limited to 'actionpack')
-rwxr-xr-xactionpack/lib/action_view/helpers/date_helper.rb31
1 files changed, 20 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index 1aee9ef0a2..fa3e612fc1 100755
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -547,23 +547,32 @@ module ActionView
# select_year(2006, :start_year => 2000, :end_year => 2010)
#
def select_year(date, options = {}, html_options = {})
- val = date ? (date.kind_of?(Fixnum) ? date : date.year) : ''
+ if !date || date == 0
+ value = ''
+ middle_year = Date.today.year
+ elsif date.kind_of?(Fixnum)
+ value = middle_year = date
+ else
+ value = middle_year = date.year
+ end
+
if options[:use_hidden]
- hidden_html(options[:field_name] || 'year', val, options)
+ hidden_html(options[:field_name] || 'year', value, options)
else
- year_options = []
- y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year
+ year_options = ''
+ start_year = options[:start_year] || middle_year - 5
+ end_year = options[:end_year] || middle_year + 5
+ step_val = start_year < end_year ? 1 : -1
- start_year, end_year = (options[:start_year] || y-5), (options[:end_year] || y+5)
- step_val = start_year < end_year ? 1 : -1
start_year.step(end_year, step_val) do |year|
- year_options << ((val == year) ?
- content_tag(:option, year, :value => year, :selected => "selected") :
- content_tag(:option, year, :value => year)
- )
+ if value == year
+ year_options << content_tag(:option, year, :value => year, :selected => "selected")
+ else
+ year_options << content_tag(:option, year, :value => year)
+ end
year_options << "\n"
end
- select_html(options[:field_name] || 'year', year_options.join, options, html_options)
+ select_html(options[:field_name] || 'year', year_options, options, html_options)
end
end