actionpack 3.0.0.beta4 → 3.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +36 -0
- data/{README → README.rdoc} +79 -137
- data/lib/abstract_controller.rb +1 -0
- data/lib/abstract_controller/asset_paths.rb +1 -1
- data/lib/abstract_controller/base.rb +3 -12
- data/lib/abstract_controller/rendering.rb +2 -2
- data/lib/abstract_controller/view_paths.rb +2 -1
- data/lib/action_controller.rb +1 -2
- data/lib/action_controller/base.rb +3 -9
- data/lib/action_controller/log_subscriber.rb +56 -0
- data/lib/action_controller/metal.rb +10 -3
- data/lib/action_controller/metal/helpers.rb +5 -4
- data/lib/action_controller/metal/hide_actions.rb +3 -3
- data/lib/action_controller/metal/instrumentation.rb +2 -1
- data/lib/action_controller/metal/mime_responds.rb +13 -10
- data/lib/action_controller/metal/rack_delegation.rb +0 -4
- data/lib/action_controller/metal/request_forgery_protection.rb +1 -1
- data/lib/action_controller/metal/rescue.rb +9 -0
- data/lib/action_controller/metal/responder.rb +13 -5
- data/lib/action_controller/metal/streaming.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +5 -5
- data/lib/action_controller/railtie.rb +14 -23
- data/lib/action_controller/record_identifier.rb +6 -25
- data/lib/action_controller/test_case.rb +18 -6
- data/lib/action_controller/vendor/html-scanner/html/node.rb +1 -0
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -0
- data/lib/action_dispatch.rb +6 -0
- data/lib/action_dispatch/http/cache.rb +2 -2
- data/lib/action_dispatch/http/filter_parameters.rb +10 -66
- data/lib/action_dispatch/http/mime_type.rb +1 -1
- data/lib/action_dispatch/http/parameter_filter.rb +72 -0
- data/lib/action_dispatch/http/parameters.rb +31 -2
- data/lib/action_dispatch/http/request.rb +4 -1
- data/lib/action_dispatch/http/upload.rb +2 -2
- data/lib/action_dispatch/middleware/callbacks.rb +4 -4
- data/lib/action_dispatch/middleware/cookies.rb +39 -6
- data/lib/action_dispatch/middleware/flash.rb +9 -2
- data/lib/action_dispatch/middleware/session/abstract_store.rb +121 -36
- data/lib/action_dispatch/middleware/session/cookie_store.rb +26 -19
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -1
- data/lib/action_dispatch/middleware/show_exceptions.rb +2 -2
- data/lib/action_dispatch/middleware/stack.rb +12 -5
- data/lib/action_dispatch/railtie.rb +1 -1
- data/lib/action_dispatch/routing.rb +11 -13
- data/lib/action_dispatch/routing/deprecated_mapper.rb +6 -388
- data/lib/action_dispatch/routing/mapper.rb +364 -234
- data/lib/action_dispatch/routing/polymorphic_routes.rb +186 -0
- data/lib/action_dispatch/routing/route.rb +11 -2
- data/lib/action_dispatch/routing/route_set.rb +62 -28
- data/lib/action_dispatch/routing/url_for.rb +2 -1
- data/lib/action_dispatch/testing/assertions.rb +0 -2
- data/lib/action_dispatch/testing/assertions/routing.rb +0 -1
- data/lib/action_dispatch/testing/assertions/selector.rb +20 -24
- data/lib/action_dispatch/testing/integration.rb +2 -2
- data/lib/action_dispatch/testing/test_response.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +1 -0
- data/lib/action_view/base.rb +20 -21
- data/lib/action_view/context.rb +9 -12
- data/lib/action_view/helpers.rb +0 -2
- data/lib/action_view/helpers/active_model_helper.rb +17 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +15 -33
- data/lib/action_view/helpers/atom_feed_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +4 -2
- data/lib/action_view/helpers/capture_helper.rb +4 -4
- data/lib/action_view/helpers/csrf_helper.rb +3 -1
- data/lib/action_view/helpers/date_helper.rb +10 -5
- data/lib/action_view/helpers/debug_helper.rb +3 -1
- data/lib/action_view/helpers/form_helper.rb +36 -30
- data/lib/action_view/helpers/form_options_helper.rb +7 -6
- data/lib/action_view/helpers/form_tag_helper.rb +17 -6
- data/lib/action_view/helpers/javascript_helper.rb +1 -0
- data/lib/action_view/helpers/number_helper.rb +16 -45
- data/lib/action_view/helpers/prototype_helper.rb +14 -16
- data/lib/action_view/helpers/raw_output_helper.rb +9 -0
- data/lib/action_view/helpers/record_tag_helper.rb +5 -0
- data/lib/action_view/helpers/sanitize_helper.rb +26 -20
- data/lib/action_view/helpers/scriptaculous_helper.rb +6 -5
- data/lib/action_view/helpers/tag_helper.rb +2 -1
- data/lib/action_view/helpers/text_helper.rb +24 -111
- data/lib/action_view/helpers/translation_helper.rb +17 -10
- data/lib/action_view/helpers/url_helper.rb +26 -33
- data/lib/action_view/log_subscriber.rb +28 -0
- data/lib/action_view/lookup_context.rb +2 -0
- data/lib/action_view/paths.rb +1 -0
- data/lib/action_view/railtie.rb +15 -3
- data/lib/action_view/render/layouts.rb +2 -1
- data/lib/action_view/render/partials.rb +3 -1
- data/lib/action_view/render/rendering.rb +2 -1
- data/lib/action_view/template.rb +12 -8
- data/lib/action_view/template/error.rb +1 -0
- data/lib/action_view/template/handlers.rb +1 -0
- data/lib/action_view/template/resolver.rb +2 -1
- data/lib/action_view/template/text.rb +1 -0
- data/lib/action_view/test_case.rb +42 -20
- metadata +44 -23
- data/lib/action_controller/polymorphic_routes.rb +0 -182
- data/lib/action_controller/railties/log_subscriber.rb +0 -56
- data/lib/action_controller/railties/url_helpers.rb +0 -14
- data/lib/action_dispatch/testing/assertions/model.rb +0 -19
- data/lib/action_view/helpers/record_identification_helper.rb +0 -20
- data/lib/action_view/railties/log_subscriber.rb +0 -24
@@ -1,3 +1,5 @@
|
|
1
|
+
require "action_controller/log_subscriber"
|
2
|
+
|
1
3
|
module ActionController
|
2
4
|
class Base < Metal
|
3
5
|
abstract!
|
@@ -26,7 +28,6 @@ module ActionController
|
|
26
28
|
SessionManagement,
|
27
29
|
Caching,
|
28
30
|
MimeResponds,
|
29
|
-
PolymorphicRoutes,
|
30
31
|
ImplicitRender,
|
31
32
|
|
32
33
|
Cookies,
|
@@ -58,19 +59,12 @@ module ActionController
|
|
58
59
|
include ActionController::Compatibility
|
59
60
|
|
60
61
|
def self.inherited(klass)
|
61
|
-
::ActionController::Base.subclasses << klass.to_s
|
62
62
|
super
|
63
63
|
klass.helper :all
|
64
64
|
end
|
65
65
|
|
66
|
-
def self.subclasses
|
67
|
-
@subclasses ||= []
|
68
|
-
end
|
69
|
-
|
70
|
-
config_accessor :asset_host, :asset_path
|
71
|
-
|
72
66
|
ActiveSupport.run_load_hooks(:action_controller, self)
|
73
67
|
end
|
74
68
|
end
|
75
69
|
|
76
|
-
require "action_controller/deprecated/base"
|
70
|
+
require "action_controller/deprecated/base"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
5
|
+
INTERNAL_PARAMS = %w(controller action format _method only_path)
|
6
|
+
|
7
|
+
def start_processing(event)
|
8
|
+
payload = event.payload
|
9
|
+
params = payload[:params].except(*INTERNAL_PARAMS)
|
10
|
+
|
11
|
+
info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
|
12
|
+
info " Parameters: #{params.inspect}" unless params.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def process_action(event)
|
16
|
+
payload = event.payload
|
17
|
+
additions = ActionController::Base.log_process_action(payload)
|
18
|
+
|
19
|
+
message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration
|
20
|
+
message << " (#{additions.join(" | ")})" unless additions.blank?
|
21
|
+
|
22
|
+
info(message)
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_file(event)
|
26
|
+
message = "Sent file %s"
|
27
|
+
message << " (%.1fms)"
|
28
|
+
info(message % [event.payload[:path], event.duration])
|
29
|
+
end
|
30
|
+
|
31
|
+
def redirect_to(event)
|
32
|
+
info "Redirected to #{event.payload[:location]}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_data(event)
|
36
|
+
info("Sent data %s (%.1fms)" % [event.payload[:filename], event.duration])
|
37
|
+
end
|
38
|
+
|
39
|
+
%w(write_fragment read_fragment exist_fragment?
|
40
|
+
expire_fragment expire_page write_page).each do |method|
|
41
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
42
|
+
def #{method}(event)
|
43
|
+
key_or_path = event.payload[:key] || event.payload[:path]
|
44
|
+
human_name = #{method.to_s.humanize.inspect}
|
45
|
+
info("\#{human_name} \#{key_or_path} (%.1fms)" % event.duration)
|
46
|
+
end
|
47
|
+
METHOD
|
48
|
+
end
|
49
|
+
|
50
|
+
def logger
|
51
|
+
ActionController::Base.logger
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
ActionController::LogSubscriber.attach_to :action_controller
|
@@ -52,8 +52,7 @@ module ActionController
|
|
52
52
|
class Metal < AbstractController::Base
|
53
53
|
abstract!
|
54
54
|
|
55
|
-
|
56
|
-
attr_internal :params, :env
|
55
|
+
attr_internal :env
|
57
56
|
|
58
57
|
# Returns the last part of the controller's name, underscored, without the ending
|
59
58
|
# "Controller". For instance, MyApp::MyPostsController would return "my_posts" for
|
@@ -62,7 +61,7 @@ module ActionController
|
|
62
61
|
# ==== Returns
|
63
62
|
# String
|
64
63
|
def self.controller_name
|
65
|
-
@controller_name ||=
|
64
|
+
@controller_name ||= self.name.demodulize.sub(/Controller$/, '').underscore
|
66
65
|
end
|
67
66
|
|
68
67
|
# Delegates to the class' #controller_name
|
@@ -85,6 +84,14 @@ module ActionController
|
|
85
84
|
super
|
86
85
|
end
|
87
86
|
|
87
|
+
def params
|
88
|
+
@_params ||= request.parameters
|
89
|
+
end
|
90
|
+
|
91
|
+
def params=(val)
|
92
|
+
@_params = val
|
93
|
+
end
|
94
|
+
|
88
95
|
# Basic implementations for content_type=, location=, and headers are
|
89
96
|
# provided to reduce the dependency on the RackDelegation module
|
90
97
|
# in Renderer and Redirector.
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/array/wrap'
|
1
2
|
require 'active_support/core_ext/class/attribute'
|
2
3
|
|
3
4
|
module ActionController
|
@@ -58,13 +59,13 @@ module ActionController
|
|
58
59
|
|
59
60
|
module ClassMethods
|
60
61
|
def helpers_dir
|
61
|
-
ActiveSupport::Deprecation.warn "helpers_dir is deprecated, use helpers_path instead"
|
62
|
+
ActiveSupport::Deprecation.warn "helpers_dir is deprecated, use helpers_path instead", caller
|
62
63
|
self.helpers_path
|
63
64
|
end
|
64
65
|
|
65
66
|
def helpers_dir=(value)
|
66
|
-
ActiveSupport::Deprecation.warn "helpers_dir= is deprecated, use helpers_path= instead"
|
67
|
-
self.helpers_path = Array(value)
|
67
|
+
ActiveSupport::Deprecation.warn "helpers_dir= is deprecated, use helpers_path= instead", caller
|
68
|
+
self.helpers_path = Array.wrap(value)
|
68
69
|
end
|
69
70
|
|
70
71
|
# Declares helper accessors for controller attributes. For example, the
|
@@ -103,7 +104,7 @@ module ActionController
|
|
103
104
|
# Extract helper names from files in app/helpers/**/*_helper.rb
|
104
105
|
def all_application_helpers
|
105
106
|
helpers = []
|
106
|
-
helpers_path.each do |path|
|
107
|
+
Array.wrap(helpers_path).each do |path|
|
107
108
|
extract = /^#{Regexp.quote(path.to_s)}\/?(.*)_helper.rb$/
|
108
109
|
helpers += Dir["#{path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') }
|
109
110
|
end
|
@@ -8,7 +8,7 @@ module ActionController
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
class_attribute :hidden_actions
|
11
|
-
self.hidden_actions = Set.new
|
11
|
+
self.hidden_actions = Set.new.freeze
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -25,7 +25,7 @@ module ActionController
|
|
25
25
|
# ==== Parameters
|
26
26
|
# *args<#to_s>:: A list of actions
|
27
27
|
def hide_action(*args)
|
28
|
-
self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s))
|
28
|
+
self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze
|
29
29
|
end
|
30
30
|
|
31
31
|
def inherited(klass)
|
@@ -41,7 +41,7 @@ module ActionController
|
|
41
41
|
# Overrides AbstractController::Base#action_methods to remove any methods
|
42
42
|
# that are listed as hidden methods.
|
43
43
|
def action_methods
|
44
|
-
@action_methods ||= Set.new(super.reject {|name| hidden_actions.include?(name)})
|
44
|
+
@action_methods ||= Set.new(super.reject { |name| hidden_actions.include?(name) })
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'benchmark'
|
1
2
|
require 'abstract_controller/logger'
|
2
3
|
|
3
4
|
module ActionController
|
4
5
|
# Adds instrumentation to several ends in ActionController::Base. It also provides
|
5
|
-
# some hooks related with process_action, this allows an ORM like
|
6
|
+
# some hooks related with process_action, this allows an ORM like Active Record
|
6
7
|
# and/or DataMapper to plug in ActionController and show related information.
|
7
8
|
#
|
8
9
|
# Check ActiveRecord::Railties::ControllerRuntime for an example.
|
@@ -12,27 +12,30 @@ module ActionController #:nodoc:
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
-
# Defines
|
15
|
+
# Defines mime types that are rendered by default when invoking
|
16
|
+
# <tt>respond_with</tt>.
|
16
17
|
#
|
17
18
|
# Examples:
|
18
19
|
#
|
19
20
|
# respond_to :html, :xml, :json
|
20
21
|
#
|
21
|
-
#
|
22
|
+
# Specifies that all actions in the controller respond to requests
|
23
|
+
# for <tt>:html</tt>, <tt>:xml</tt> and <tt>:json</tt>.
|
22
24
|
#
|
23
|
-
#
|
24
|
-
# except:
|
25
|
+
# To specify on per-action basis, use <tt>:only</tt> and
|
26
|
+
# <tt>:except</tt> with an array of actions or a single action:
|
25
27
|
#
|
26
28
|
# respond_to :html
|
27
29
|
# respond_to :xml, :json, :except => [ :edit ]
|
28
30
|
#
|
29
|
-
#
|
30
|
-
# actions except
|
31
|
-
#
|
32
|
-
# You can specify also only parameters:
|
31
|
+
# This specifies that all actions respond to <tt>:html</tt>
|
32
|
+
# and all actions except <tt>:edit</tt> respond to <tt>:xml</tt> and
|
33
|
+
# <tt>:json</tt>.
|
33
34
|
#
|
34
35
|
# respond_to :rjs, :only => :create
|
35
36
|
#
|
37
|
+
# This specifies that the <tt>:create</tt> action and no other responds
|
38
|
+
# to <tt>:rjs</tt>.
|
36
39
|
def respond_to(*mimes)
|
37
40
|
options = mimes.extract_options!
|
38
41
|
|
@@ -49,7 +52,7 @@ module ActionController #:nodoc:
|
|
49
52
|
self.mimes_for_respond_to = new.freeze
|
50
53
|
end
|
51
54
|
|
52
|
-
# Clear all
|
55
|
+
# Clear all mime types in <tt>respond_to</tt>.
|
53
56
|
#
|
54
57
|
def clear_respond_to
|
55
58
|
self.mimes_for_respond_to = ActiveSupport::OrderedHash.new.freeze
|
@@ -145,7 +148,7 @@ module ActionController #:nodoc:
|
|
145
148
|
# and accept Rails' defaults, life will be much easier.
|
146
149
|
#
|
147
150
|
# If you need to use a MIME type which isn't supported by default, you can register your own handlers in
|
148
|
-
#
|
151
|
+
# config/initializers/mime_types.rb as follows.
|
149
152
|
#
|
150
153
|
# Mime::Type.register "image/jpg", :jpg
|
151
154
|
#
|
@@ -55,7 +55,7 @@ module ActionController #:nodoc:
|
|
55
55
|
config_accessor :request_forgery_protection_token
|
56
56
|
self.request_forgery_protection_token ||= :authenticity_token
|
57
57
|
|
58
|
-
# Controls whether request
|
58
|
+
# Controls whether request forgery protection is turned on or not. Turned off by default only in test mode.
|
59
59
|
config_accessor :allow_forgery_protection
|
60
60
|
self.allow_forgery_protection = true if allow_forgery_protection.nil?
|
61
61
|
|
@@ -3,6 +3,15 @@ module ActionController #:nodoc:
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
include ActiveSupport::Rescuable
|
5
5
|
|
6
|
+
def rescue_with_handler(exception)
|
7
|
+
if (exception.respond_to?(:original_exception) &&
|
8
|
+
(orig_exception = exception.original_exception) &&
|
9
|
+
handler_for_rescue(orig_exception))
|
10
|
+
exception = orig_exception
|
11
|
+
end
|
12
|
+
super(exception)
|
13
|
+
end
|
14
|
+
|
6
15
|
private
|
7
16
|
def process_action(*args)
|
8
17
|
super
|
@@ -89,9 +89,7 @@ module ActionController #:nodoc:
|
|
89
89
|
|
90
90
|
def initialize(controller, resources, options={})
|
91
91
|
@controller = controller
|
92
|
-
@
|
93
|
-
@format = controller.formats.first
|
94
|
-
@resource = resources.is_a?(Array) ? resources.last : resources
|
92
|
+
@resource = resources.last
|
95
93
|
@resources = resources
|
96
94
|
@options = options
|
97
95
|
@action = options.delete(:action)
|
@@ -101,6 +99,14 @@ module ActionController #:nodoc:
|
|
101
99
|
delegate :head, :render, :redirect_to, :to => :controller
|
102
100
|
delegate :get?, :post?, :put?, :delete?, :to => :request
|
103
101
|
|
102
|
+
def request
|
103
|
+
@request ||= @controller.request
|
104
|
+
end
|
105
|
+
|
106
|
+
def format
|
107
|
+
@format ||= @controller.formats.first
|
108
|
+
end
|
109
|
+
|
104
110
|
# Undefine :to_json and :to_yaml since it's defined on Object
|
105
111
|
undef_method(:to_json) if method_defined?(:to_json)
|
106
112
|
undef_method(:to_yaml) if method_defined?(:to_yaml)
|
@@ -147,7 +153,7 @@ module ActionController #:nodoc:
|
|
147
153
|
elsif has_errors? && default_action
|
148
154
|
render :action => default_action
|
149
155
|
else
|
150
|
-
redirect_to
|
156
|
+
redirect_to navigation_location
|
151
157
|
end
|
152
158
|
end
|
153
159
|
|
@@ -160,7 +166,7 @@ module ActionController #:nodoc:
|
|
160
166
|
elsif has_errors?
|
161
167
|
display resource.errors, :status => :unprocessable_entity
|
162
168
|
elsif post?
|
163
|
-
display resource, :status => :created, :location =>
|
169
|
+
display resource, :status => :created, :location => api_location
|
164
170
|
else
|
165
171
|
head :ok
|
166
172
|
end
|
@@ -178,6 +184,8 @@ module ActionController #:nodoc:
|
|
178
184
|
def resource_location
|
179
185
|
options[:location] || resources
|
180
186
|
end
|
187
|
+
alias :navigation_location :resource_location
|
188
|
+
alias :api_location :resource_location
|
181
189
|
|
182
190
|
# If a given response block was given, use it, otherwise call render on
|
183
191
|
# controller.
|
@@ -12,17 +12,17 @@ module ActionController
|
|
12
12
|
).merge(:script_name => request.script_name)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
raise "In order to use #url_for, you must include
|
17
|
-
"
|
15
|
+
def _routes
|
16
|
+
raise "In order to use #url_for, you must include routing helpers explicitly. " \
|
17
|
+
"For instance, `include Rails.application.routes.url_helpers"
|
18
18
|
end
|
19
19
|
|
20
20
|
module ClassMethods
|
21
21
|
def action_methods
|
22
22
|
@action_methods ||= begin
|
23
|
-
super -
|
23
|
+
super - _routes.named_routes.helper_names
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -2,13 +2,9 @@ require "rails"
|
|
2
2
|
require "action_controller"
|
3
3
|
require "action_dispatch/railtie"
|
4
4
|
require "action_view/railtie"
|
5
|
-
require "active_support/core_ext/class/subclasses"
|
6
5
|
require "active_support/deprecation/proxy_wrappers"
|
7
6
|
require "active_support/deprecation"
|
8
7
|
|
9
|
-
require "action_controller/railties/log_subscriber"
|
10
|
-
require "action_controller/railties/url_helpers"
|
11
|
-
|
12
8
|
module ActionController
|
13
9
|
class Railtie < Rails::Railtie
|
14
10
|
config.action_controller = ActiveSupport::OrderedOptions.new
|
@@ -35,23 +31,6 @@ module ActionController
|
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new
|
39
|
-
|
40
|
-
initializer "action_controller.set_configs" do |app|
|
41
|
-
paths = app.config.paths
|
42
|
-
ac = app.config.action_controller
|
43
|
-
|
44
|
-
ac.assets_dir ||= paths.public.to_a.first
|
45
|
-
ac.javascripts_dir ||= paths.public.javascripts.to_a.first
|
46
|
-
ac.stylesheets_dir ||= paths.public.stylesheets.to_a.first
|
47
|
-
ac.page_cache_directory ||= paths.public.to_a.first
|
48
|
-
ac.helpers_path ||= paths.app.helpers.to_a
|
49
|
-
|
50
|
-
ActiveSupport.on_load(:action_controller) do
|
51
|
-
self.config.merge!(ac)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
34
|
initializer "action_controller.logger" do
|
56
35
|
ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger }
|
57
36
|
end
|
@@ -60,11 +39,23 @@ module ActionController
|
|
60
39
|
ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE }
|
61
40
|
end
|
62
41
|
|
63
|
-
initializer "action_controller.
|
42
|
+
initializer "action_controller.set_configs" do |app|
|
43
|
+
paths = app.config.paths
|
44
|
+
options = app.config.action_controller
|
45
|
+
|
46
|
+
options.assets_dir ||= paths.public.to_a.first
|
47
|
+
options.javascripts_dir ||= paths.public.javascripts.to_a.first
|
48
|
+
options.stylesheets_dir ||= paths.public.stylesheets.to_a.first
|
49
|
+
options.page_cache_directory ||= paths.public.to_a.first
|
50
|
+
options.helpers_path ||= paths.app.helpers.to_a
|
51
|
+
|
64
52
|
ActiveSupport.on_load(:action_controller) do
|
65
|
-
|
53
|
+
include app.routes.url_helpers
|
54
|
+
options.each { |k,v| send("#{k}=", v) }
|
66
55
|
end
|
56
|
+
end
|
67
57
|
|
58
|
+
initializer "action_controller.deprecated_routes" do |app|
|
68
59
|
message = "ActionController::Routing::Routes is deprecated. " \
|
69
60
|
"Instead, use Rails.application.routes"
|
70
61
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_support/core_ext/module'
|
2
2
|
|
3
3
|
module ActionController
|
4
|
-
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
|
4
|
+
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or
|
5
5
|
# Active Resources or pretty much any other model type that has an id. These patterns are then used to try elevate
|
6
6
|
# the view actions to a higher logical level. Example:
|
7
7
|
#
|
@@ -28,7 +28,7 @@ module ActionController
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
# As the example above shows, you can stop caring to a large extent what the actual id of the post is. You just know
|
31
|
-
# that one is being assigned and that the subsequent calls in redirect_to and the RJS expect that same naming
|
31
|
+
# that one is being assigned and that the subsequent calls in redirect_to and the RJS expect that same naming
|
32
32
|
# convention and allows you to write less code if you follow it.
|
33
33
|
module RecordIdentifier
|
34
34
|
extend self
|
@@ -46,7 +46,7 @@ module ActionController
|
|
46
46
|
# dom_class(post, :edit) # => "edit_post"
|
47
47
|
# dom_class(Person, :edit) # => "edit_person"
|
48
48
|
def dom_class(record_or_class, prefix = nil)
|
49
|
-
singular =
|
49
|
+
singular = ActiveModel::Naming.singular(record_or_class)
|
50
50
|
prefix ? "#{prefix}#{JOIN}#{singular}" : singular
|
51
51
|
end
|
52
52
|
|
@@ -59,7 +59,7 @@ module ActionController
|
|
59
59
|
# If you need to address multiple instances of the same class in the same view, you can prefix the dom_id:
|
60
60
|
#
|
61
61
|
# dom_id(Post.find(45), :edit) # => "edit_post_45"
|
62
|
-
def dom_id(record, prefix = nil)
|
62
|
+
def dom_id(record, prefix = nil)
|
63
63
|
if record_id = record_key_for_dom_id(record)
|
64
64
|
"#{dom_class(record, prefix)}#{JOIN}#{record_id}"
|
65
65
|
else
|
@@ -67,6 +67,8 @@ module ActionController
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
protected
|
71
|
+
|
70
72
|
# Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id.
|
71
73
|
# This can be overwritten to customize the default generated string representation if desired.
|
72
74
|
# If you need to read back a key from a dom_id in order to query for the underlying database record,
|
@@ -85,26 +87,5 @@ module ActionController
|
|
85
87
|
def sanitize_dom_id(candidate_id)
|
86
88
|
candidate_id # TODO implement conversion to valid DOM id values
|
87
89
|
end
|
88
|
-
|
89
|
-
# Returns the plural class name of a record or class. Examples:
|
90
|
-
#
|
91
|
-
# plural_class_name(post) # => "posts"
|
92
|
-
# plural_class_name(Highrise::Person) # => "highrise_people"
|
93
|
-
def plural_class_name(record_or_class)
|
94
|
-
model_name_from_record_or_class(record_or_class).plural
|
95
|
-
end
|
96
|
-
|
97
|
-
# Returns the singular class name of a record or class. Examples:
|
98
|
-
#
|
99
|
-
# singular_class_name(post) # => "post"
|
100
|
-
# singular_class_name(Highrise::Person) # => "highrise_person"
|
101
|
-
def singular_class_name(record_or_class)
|
102
|
-
model_name_from_record_or_class(record_or_class).singular
|
103
|
-
end
|
104
|
-
|
105
|
-
private
|
106
|
-
def model_name_from_record_or_class(record_or_class)
|
107
|
-
(record_or_class.is_a?(Class) ? record_or_class : record_or_class.class).model_name
|
108
|
-
end
|
109
90
|
end
|
110
91
|
end
|