aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller.rb1
-rw-r--r--actionpack/lib/abstract_controller/helpers.rb7
-rw-r--r--actionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb30
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb11
-rw-r--r--actionpack/lib/action_view/template.rb6
6 files changed, 33 insertions, 24 deletions
diff --git a/actionpack/lib/abstract_controller.rb b/actionpack/lib/abstract_controller.rb
index c565c940a1..f8fc79936f 100644
--- a/actionpack/lib/abstract_controller.rb
+++ b/actionpack/lib/abstract_controller.rb
@@ -2,6 +2,7 @@ activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
require 'action_pack'
+require 'active_support/concern'
require 'active_support/ruby/shim'
require 'active_support/dependencies/autoload'
require 'active_support/core_ext/class/attribute'
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index 0c96a6ed15..a0ce121ade 100644
--- a/actionpack/lib/abstract_controller/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
@@ -95,6 +95,13 @@ module AbstractController
_helpers.module_eval(&block) if block_given?
end
+ # Clears up all existing helpers in this class, only keeping the helper
+ # with the same name as this class.
+ def clear_helpers
+ self._helpers = Module.new
+ default_helper_module! unless anonymous?
+ end
+
private
# Makes all the (instance) methods in the helper module available to templates
# rendered through this controller.
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 165bf089c0..d8d3a2335a 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -223,7 +223,7 @@ module ActionController
def self.inherited(klass)
super
- klass.helper :all
+ klass.helper :all if klass.superclass == ActionController::Base
end
ActiveSupport.run_load_hooks(:action_controller, self)
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index 8050669adb..9891478606 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -1,6 +1,7 @@
-require "date"
+require 'date'
require 'action_view/helpers/tag_helper'
require 'active_support/core_ext/hash/slice'
+require 'active_support/core_ext/object/with_options'
module ActionView
module Helpers
@@ -751,10 +752,8 @@ module ActionView
# => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun",
# "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
def translated_month_names
- begin
- key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
- I18n.translate(key, :locale => @options[:locale])
- end
+ key = @options[:use_short_month] ? :'date.abbr_month_names' : :'date.month_names'
+ I18n.translate(key, :locale => @options[:locale])
end
# Lookup month name for number
@@ -781,9 +780,7 @@ module ActionView
memoize :date_order
def translated_date_order
- begin
- I18n.translate(:'date.order', :locale => @options[:locale]) || []
- end
+ I18n.translate(:'date.order', :locale => @options[:locale]) || []
end
# Build full select tag from date type and options
@@ -837,15 +834,14 @@ module ActionView
# prompt_option_tag(:month, :prompt => 'Select month')
# => "<option value="">Select month</option>"
def prompt_option_tag(type, options)
- default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false}
-
- case options
- when Hash
- prompt = default_options.merge(options)[type.to_sym]
- when String
- prompt = options
- else
- prompt = I18n.translate(('datetime.prompts.' + type.to_s).to_sym, :locale => @options[:locale])
+ prompt = case options
+ when Hash
+ default_options = {:year => false, :month => false, :day => false, :hour => false, :minute => false, :second => false}
+ default_options.merge!(options)[type.to_sym]
+ when String
+ options
+ else
+ I18n.translate(:"datetime.prompts.#{type}", :locale => @options[:locale])
end
prompt ? content_tag(:option, prompt, :value => '') : ''
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index ebe055bebd..938da7aea7 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -1006,9 +1006,14 @@ module ActionView
def value_before_type_cast(object, method_name)
unless object.nil?
- object.respond_to?(method_name) ?
- object.send(method_name) :
- object.send(method_name + "_before_type_cast")
+ if object.respond_to?(method_name)
+ object.send(method_name)
+ # FIXME: this is AR dependent
+ elsif object.respond_to?(method_name + "_before_type_cast")
+ object.send(method_name + "_before_type_cast")
+ else
+ raise NoMethodError, "Model #{object.class} does not respond to #{method_name}"
+ end
end
end
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index 40ff1f2182..a999a0b7d7 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/object/try'
require 'active_support/core_ext/kernel/singleton_class'
module ActionView
@@ -113,12 +114,11 @@ module ActionView
@identifier = identifier
@handler = handler
@original_encoding = nil
-
- @virtual_path = details[:virtual_path]
- @method_names = {}
+ @method_names = {}
format = details[:format] || :html
@formats = Array.wrap(format).map(&:to_sym)
+ @virtual_path = details[:virtual_path].try(:sub, ".#{format}", "")
end
def render(view, locals, &block)