actionpack 4.2.11.3 → 5.0.0.beta1
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +379 -462
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -3
- data/lib/abstract_controller.rb +0 -2
- data/lib/abstract_controller/base.rb +17 -32
- data/lib/abstract_controller/callbacks.rb +52 -19
- data/lib/abstract_controller/collector.rb +4 -9
- data/lib/abstract_controller/helpers.rb +2 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -2
- data/lib/abstract_controller/rendering.rb +27 -22
- data/lib/abstract_controller/translation.rb +8 -7
- data/lib/action_controller.rb +4 -3
- data/lib/action_controller/api.rb +146 -0
- data/lib/action_controller/base.rb +6 -10
- data/lib/action_controller/caching.rb +1 -3
- data/lib/action_controller/caching/fragments.rb +48 -3
- data/lib/action_controller/form_builder.rb +48 -0
- data/lib/action_controller/log_subscriber.rb +1 -10
- data/lib/action_controller/metal.rb +89 -62
- data/lib/action_controller/metal/basic_implicit_render.rb +11 -0
- data/lib/action_controller/metal/conditional_get.rb +65 -24
- data/lib/action_controller/metal/cookies.rb +0 -2
- data/lib/action_controller/metal/data_streaming.rb +2 -22
- data/lib/action_controller/metal/etag_with_template_digest.rb +1 -1
- data/lib/action_controller/metal/exceptions.rb +11 -6
- data/lib/action_controller/metal/force_ssl.rb +6 -6
- data/lib/action_controller/metal/head.rb +14 -7
- data/lib/action_controller/metal/helpers.rb +9 -5
- data/lib/action_controller/metal/http_authentication.rb +37 -38
- data/lib/action_controller/metal/implicit_render.rb +23 -6
- data/lib/action_controller/metal/instrumentation.rb +0 -1
- data/lib/action_controller/metal/live.rb +17 -55
- data/lib/action_controller/metal/mime_responds.rb +17 -37
- data/lib/action_controller/metal/params_wrapper.rb +8 -8
- data/lib/action_controller/metal/redirecting.rb +32 -9
- data/lib/action_controller/metal/renderers.rb +10 -8
- data/lib/action_controller/metal/rendering.rb +38 -6
- data/lib/action_controller/metal/request_forgery_protection.rb +67 -35
- data/lib/action_controller/metal/rescue.rb +2 -4
- data/lib/action_controller/metal/streaming.rb +4 -4
- data/lib/action_controller/metal/strong_parameters.rb +231 -78
- data/lib/action_controller/metal/testing.rb +1 -12
- data/lib/action_controller/metal/url_for.rb +12 -5
- data/lib/action_controller/renderer.rb +111 -0
- data/lib/action_controller/template_assertions.rb +9 -0
- data/lib/action_controller/test_case.rb +267 -363
- data/lib/action_dispatch.rb +2 -1
- data/lib/action_dispatch/http/cache.rb +23 -26
- data/lib/action_dispatch/http/filter_parameters.rb +6 -8
- data/lib/action_dispatch/http/filter_redirect.rb +7 -8
- data/lib/action_dispatch/http/headers.rb +28 -11
- data/lib/action_dispatch/http/mime_negotiation.rb +40 -26
- data/lib/action_dispatch/http/mime_type.rb +92 -61
- data/lib/action_dispatch/http/mime_types.rb +1 -4
- data/lib/action_dispatch/http/parameter_filter.rb +18 -8
- data/lib/action_dispatch/http/parameters.rb +45 -41
- data/lib/action_dispatch/http/request.rb +146 -82
- data/lib/action_dispatch/http/response.rb +180 -99
- data/lib/action_dispatch/http/url.rb +117 -8
- data/lib/action_dispatch/journey/formatter.rb +34 -28
- data/lib/action_dispatch/journey/gtg/transition_table.rb +1 -1
- data/lib/action_dispatch/journey/nfa/dot.rb +0 -2
- data/lib/action_dispatch/journey/nfa/transition_table.rb +1 -46
- data/lib/action_dispatch/journey/nodes/node.rb +14 -4
- data/lib/action_dispatch/journey/parser_extras.rb +4 -0
- data/lib/action_dispatch/journey/path/pattern.rb +37 -41
- data/lib/action_dispatch/journey/route.rb +71 -17
- data/lib/action_dispatch/journey/router.rb +5 -6
- data/lib/action_dispatch/journey/router/utils.rb +5 -5
- data/lib/action_dispatch/journey/routes.rb +14 -15
- data/lib/action_dispatch/journey/visitors.rb +86 -43
- data/lib/action_dispatch/middleware/cookies.rb +184 -135
- data/lib/action_dispatch/middleware/debug_exceptions.rb +115 -45
- data/lib/action_dispatch/middleware/exception_wrapper.rb +21 -20
- data/lib/action_dispatch/middleware/flash.rb +61 -45
- data/lib/action_dispatch/middleware/load_interlock.rb +21 -0
- data/lib/action_dispatch/middleware/params_parser.rb +30 -46
- data/lib/action_dispatch/middleware/public_exceptions.rb +2 -2
- data/lib/action_dispatch/middleware/reloader.rb +2 -4
- data/lib/action_dispatch/middleware/remote_ip.rb +29 -19
- data/lib/action_dispatch/middleware/request_id.rb +11 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +23 -11
- data/lib/action_dispatch/middleware/session/cache_store.rb +9 -6
- data/lib/action_dispatch/middleware/session/cookie_store.rb +29 -23
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +4 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +11 -9
- data/lib/action_dispatch/middleware/ssl.rb +93 -36
- data/lib/action_dispatch/middleware/stack.rb +43 -48
- data/lib/action_dispatch/middleware/static.rb +52 -40
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +59 -63
- data/lib/action_dispatch/railtie.rb +0 -2
- data/lib/action_dispatch/request/session.rb +66 -34
- data/lib/action_dispatch/request/utils.rb +51 -19
- data/lib/action_dispatch/routing.rb +3 -8
- data/lib/action_dispatch/routing/inspector.rb +6 -30
- data/lib/action_dispatch/routing/mapper.rb +447 -322
- data/lib/action_dispatch/routing/polymorphic_routes.rb +8 -14
- data/lib/action_dispatch/routing/redirection.rb +3 -3
- data/lib/action_dispatch/routing/route_set.rb +124 -227
- data/lib/action_dispatch/routing/url_for.rb +27 -10
- data/lib/action_dispatch/testing/assertions.rb +1 -1
- data/lib/action_dispatch/testing/assertions/response.rb +27 -9
- data/lib/action_dispatch/testing/assertions/routing.rb +9 -9
- data/lib/action_dispatch/testing/integration.rb +237 -76
- data/lib/action_dispatch/testing/test_process.rb +5 -5
- data/lib/action_dispatch/testing/test_request.rb +12 -21
- data/lib/action_dispatch/testing/test_response.rb +1 -4
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/gem_version.rb +4 -4
- metadata +26 -25
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -28,11 +28,11 @@ can be used outside of Rails.
|
|
28
28
|
|
29
29
|
The latest version of Action Pack can be installed with RubyGems:
|
30
30
|
|
31
|
-
|
31
|
+
$ gem install actionpack
|
32
32
|
|
33
33
|
Source code can be downloaded as part of the Rails project on GitHub
|
34
34
|
|
35
|
-
* https://github.com/rails/rails/tree/
|
35
|
+
* https://github.com/rails/rails/tree/master/actionpack
|
36
36
|
|
37
37
|
|
38
38
|
== License
|
@@ -55,4 +55,3 @@ Bug reports can be filed for the Ruby on Rails project here:
|
|
55
55
|
Feature requests should be discussed on the rails-core mailing list here:
|
56
56
|
|
57
57
|
* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
|
58
|
-
|
data/lib/abstract_controller.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'erubis'
|
2
|
-
require 'set'
|
3
2
|
require 'active_support/configurable'
|
4
3
|
require 'active_support/descendants_tracker'
|
5
4
|
require 'active_support/core_ext/module/anonymous'
|
5
|
+
require 'active_support/core_ext/module/attr_internal'
|
6
6
|
|
7
7
|
module AbstractController
|
8
8
|
class Error < StandardError #:nodoc:
|
@@ -12,7 +12,7 @@ module AbstractController
|
|
12
12
|
class ActionNotFound < StandardError
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# AbstractController::Base is a low-level API. Nobody should be
|
16
16
|
# using it directly, and subclasses (like ActionController::Base) are
|
17
17
|
# expected to provide their own +render+ method, since rendering means
|
18
18
|
# different things depending on the context.
|
@@ -57,21 +57,11 @@ module AbstractController
|
|
57
57
|
controller.public_instance_methods(true)
|
58
58
|
end
|
59
59
|
|
60
|
-
# The list of hidden actions. Defaults to an empty array.
|
61
|
-
# This can be modified by other modules or subclasses
|
62
|
-
# to specify particular actions as hidden.
|
63
|
-
#
|
64
|
-
# ==== Returns
|
65
|
-
# * <tt>Array</tt> - An array of method names that should not be considered actions.
|
66
|
-
def hidden_actions
|
67
|
-
[]
|
68
|
-
end
|
69
|
-
|
70
60
|
# A list of method names that should be considered actions. This
|
71
61
|
# includes all public instance methods on a controller, less
|
72
|
-
# any internal methods (see
|
62
|
+
# any internal methods (see internal_methods), adding back in
|
73
63
|
# any methods that are internal, but still exist on the class
|
74
|
-
# itself.
|
64
|
+
# itself.
|
75
65
|
#
|
76
66
|
# ==== Returns
|
77
67
|
# * <tt>Set</tt> - A set of all methods that should be considered actions.
|
@@ -82,30 +72,31 @@ module AbstractController
|
|
82
72
|
# Except for public instance methods of Base and its ancestors
|
83
73
|
internal_methods +
|
84
74
|
# Be sure to include shadowed public instance methods of this class
|
85
|
-
public_instance_methods(false)).uniq.map
|
86
|
-
# And always exclude explicitly hidden actions
|
87
|
-
hidden_actions.to_a
|
75
|
+
public_instance_methods(false)).uniq.map(&:to_s)
|
88
76
|
|
89
|
-
|
90
|
-
Set.new(methods.reject { |method| method =~ /_one_time_conditions/ })
|
77
|
+
methods.to_set
|
91
78
|
end
|
92
79
|
end
|
93
80
|
|
94
81
|
# action_methods are cached and there is sometimes need to refresh
|
95
|
-
# them. clear_action_methods! allows you to do that, so next time
|
82
|
+
# them. ::clear_action_methods! allows you to do that, so next time
|
96
83
|
# you run action_methods, they will be recalculated
|
97
84
|
def clear_action_methods!
|
98
85
|
@action_methods = nil
|
99
86
|
end
|
100
87
|
|
101
88
|
# Returns the full controller name, underscored, without the ending Controller.
|
102
|
-
#
|
103
|
-
#
|
89
|
+
#
|
90
|
+
# class MyApp::MyPostsController < AbstractController::Base
|
91
|
+
#
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# MyApp::MyPostsController.controller_path # => "my_app/my_posts"
|
104
95
|
#
|
105
96
|
# ==== Returns
|
106
97
|
# * <tt>String</tt>
|
107
98
|
def controller_path
|
108
|
-
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
|
99
|
+
@controller_path ||= name.sub(/Controller$/, ''.freeze).underscore unless anonymous?
|
109
100
|
end
|
110
101
|
|
111
102
|
# Refresh the cached action_methods when a new action_method is added.
|
@@ -137,12 +128,12 @@ module AbstractController
|
|
137
128
|
process_action(action_name, *args)
|
138
129
|
end
|
139
130
|
|
140
|
-
# Delegates to the class'
|
131
|
+
# Delegates to the class' ::controller_path
|
141
132
|
def controller_path
|
142
133
|
self.class.controller_path
|
143
134
|
end
|
144
135
|
|
145
|
-
# Delegates to the class'
|
136
|
+
# Delegates to the class' ::action_methods
|
146
137
|
def action_methods
|
147
138
|
self.class.action_methods
|
148
139
|
end
|
@@ -157,11 +148,8 @@ module AbstractController
|
|
157
148
|
#
|
158
149
|
# ==== Parameters
|
159
150
|
# * <tt>action_name</tt> - The name of an action to be tested
|
160
|
-
#
|
161
|
-
# ==== Returns
|
162
|
-
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
163
151
|
def available_action?(action_name)
|
164
|
-
_find_action_name(action_name)
|
152
|
+
_find_action_name(action_name)
|
165
153
|
end
|
166
154
|
|
167
155
|
# Returns true if the given controller is capable of rendering
|
@@ -180,9 +168,6 @@ module AbstractController
|
|
180
168
|
# ==== Parameters
|
181
169
|
# * <tt>name</tt> - The name of an action to be tested
|
182
170
|
#
|
183
|
-
# ==== Returns
|
184
|
-
# * <tt>TrueClass</tt>, <tt>FalseClass</tt>
|
185
|
-
#
|
186
171
|
# :api: private
|
187
172
|
def action_method?(name)
|
188
173
|
self.class.action_methods.include?(name)
|
@@ -9,7 +9,7 @@ module AbstractController
|
|
9
9
|
|
10
10
|
included do
|
11
11
|
define_callbacks :process_action,
|
12
|
-
terminator: ->(controller,
|
12
|
+
terminator: ->(controller, result_lambda) { result_lambda.call if result_lambda.is_a?(Proc); controller.response_body },
|
13
13
|
skip_after_callbacks_if_terminated: true
|
14
14
|
end
|
15
15
|
|
@@ -22,14 +22,25 @@ module AbstractController
|
|
22
22
|
end
|
23
23
|
|
24
24
|
module ClassMethods
|
25
|
-
# If
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
25
|
+
# If +:only+ or +:except+ are used, convert the options into the
|
26
|
+
# +:if+ and +:unless+ options of ActiveSupport::Callbacks.
|
27
|
+
#
|
28
|
+
# The basic idea is that <tt>:only => :index</tt> gets converted to
|
29
|
+
# <tt>:if => proc {|c| c.action_name == "index" }</tt>.
|
30
|
+
#
|
31
|
+
# Note that <tt>:only</tt> has priority over <tt>:if</tt> in case they
|
32
|
+
# are used together.
|
33
|
+
#
|
34
|
+
# only: :index, if: -> { true } # the :if option will be ignored.
|
35
|
+
#
|
36
|
+
# Note that <tt>:if</tt> has priority over <tt>:except</tt> in case they
|
37
|
+
# are used together.
|
38
|
+
#
|
39
|
+
# except: :index, if: -> { true } # the :except option will be ignored.
|
29
40
|
#
|
30
41
|
# ==== Options
|
31
|
-
# * <tt>only</tt> - The callback should be run only for this action
|
32
|
-
# * <tt>except</tt> - The callback should be run for all actions except this action
|
42
|
+
# * <tt>only</tt> - The callback should be run only for this action.
|
43
|
+
# * <tt>except</tt> - The callback should be run for all actions except this action.
|
33
44
|
def _normalize_callback_options(options)
|
34
45
|
_normalize_callback_option(options, :only, :if)
|
35
46
|
_normalize_callback_option(options, :except, :unless)
|
@@ -37,7 +48,8 @@ module AbstractController
|
|
37
48
|
|
38
49
|
def _normalize_callback_option(options, from, to) # :nodoc:
|
39
50
|
if from = options[from]
|
40
|
-
|
51
|
+
_from = Array(from).map(&:to_s).to_set
|
52
|
+
from = proc {|c| _from.include? c.action_name }
|
41
53
|
options[to] = Array(options[to]).unshift(from)
|
42
54
|
end
|
43
55
|
end
|
@@ -48,13 +60,18 @@ module AbstractController
|
|
48
60
|
# * <tt>names</tt> - A list of valid names that could be used for
|
49
61
|
# callbacks. Note that skipping uses Ruby equality, so it's
|
50
62
|
# impossible to skip a callback defined using an anonymous proc
|
51
|
-
# using #skip_action_callback
|
63
|
+
# using #skip_action_callback.
|
52
64
|
def skip_action_callback(*names)
|
53
|
-
skip_before_action
|
54
|
-
|
55
|
-
|
65
|
+
ActiveSupport::Deprecation.warn('`skip_action_callback` is deprecated and will be removed in Rails 5.1. Please use skip_before_action, skip_after_action or skip_around_action instead.')
|
66
|
+
skip_before_action(*names, raise: false)
|
67
|
+
skip_after_action(*names, raise: false)
|
68
|
+
skip_around_action(*names, raise: false)
|
69
|
+
end
|
70
|
+
|
71
|
+
def skip_filter(*names)
|
72
|
+
ActiveSupport::Deprecation.warn("`skip_filter` is deprecated and will be removed in Rails 5.1. Use skip_before_action, skip_after_action or skip_around_action instead.")
|
73
|
+
skip_action_callback(*names)
|
56
74
|
end
|
57
|
-
alias_method :skip_filter, :skip_action_callback
|
58
75
|
|
59
76
|
# Take callback names and an optional callback proc, normalize them,
|
60
77
|
# then call the block with each callback. This allows us to abstract
|
@@ -66,8 +83,8 @@ module AbstractController
|
|
66
83
|
# * <tt>block</tt> - A proc that should be added to the callbacks.
|
67
84
|
#
|
68
85
|
# ==== Block Parameters
|
69
|
-
# * <tt>name</tt> - The callback to be added
|
70
|
-
# * <tt>options</tt> - A hash of options to be used when adding the callback
|
86
|
+
# * <tt>name</tt> - The callback to be added.
|
87
|
+
# * <tt>options</tt> - A hash of options to be used when adding the callback.
|
71
88
|
def _insert_callbacks(callbacks, block = nil)
|
72
89
|
options = callbacks.extract_options!
|
73
90
|
_normalize_callback_options(options)
|
@@ -169,14 +186,22 @@ module AbstractController
|
|
169
186
|
set_callback(:process_action, callback, name, options)
|
170
187
|
end
|
171
188
|
end
|
172
|
-
|
189
|
+
|
190
|
+
define_method "#{callback}_filter" do |*names, &blk|
|
191
|
+
ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will be removed in Rails 5.1. Use #{callback}_action instead.")
|
192
|
+
send("#{callback}_action", *names, &blk)
|
193
|
+
end
|
173
194
|
|
174
195
|
define_method "prepend_#{callback}_action" do |*names, &blk|
|
175
196
|
_insert_callbacks(names, blk) do |name, options|
|
176
197
|
set_callback(:process_action, callback, name, options.merge(:prepend => true))
|
177
198
|
end
|
178
199
|
end
|
179
|
-
|
200
|
+
|
201
|
+
define_method "prepend_#{callback}_filter" do |*names, &blk|
|
202
|
+
ActiveSupport::Deprecation.warn("prepend_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use prepend_#{callback}_action instead.")
|
203
|
+
send("prepend_#{callback}_action", *names, &blk)
|
204
|
+
end
|
180
205
|
|
181
206
|
# Skip a before, after or around callback. See _insert_callbacks
|
182
207
|
# for details on the allowed parameters.
|
@@ -185,11 +210,19 @@ module AbstractController
|
|
185
210
|
skip_callback(:process_action, callback, name, options)
|
186
211
|
end
|
187
212
|
end
|
188
|
-
|
213
|
+
|
214
|
+
define_method "skip_#{callback}_filter" do |*names, &blk|
|
215
|
+
ActiveSupport::Deprecation.warn("skip_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use skip_#{callback}_action instead.")
|
216
|
+
send("skip_#{callback}_action", *names, &blk)
|
217
|
+
end
|
189
218
|
|
190
219
|
# *_action is the same as append_*_action
|
191
220
|
alias_method :"append_#{callback}_action", :"#{callback}_action"
|
192
|
-
|
221
|
+
|
222
|
+
define_method "append_#{callback}_filter" do |*names, &blk|
|
223
|
+
ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use append_#{callback}_action instead.")
|
224
|
+
send("append_#{callback}_action", *names, &blk)
|
225
|
+
end
|
193
226
|
end
|
194
227
|
end
|
195
228
|
end
|
@@ -4,11 +4,10 @@ module AbstractController
|
|
4
4
|
module Collector
|
5
5
|
def self.generate_method_for_mime(mime)
|
6
6
|
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
|
7
|
-
const = sym.upcase
|
8
7
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
|
-
def #{sym}(*args, &block)
|
10
|
-
custom(Mime
|
11
|
-
end
|
8
|
+
def #{sym}(*args, &block)
|
9
|
+
custom(Mime[:#{sym}], *args, &block)
|
10
|
+
end
|
12
11
|
RUBY
|
13
12
|
end
|
14
13
|
|
@@ -23,9 +22,7 @@ module AbstractController
|
|
23
22
|
protected
|
24
23
|
|
25
24
|
def method_missing(symbol, &block)
|
26
|
-
|
27
|
-
|
28
|
-
unless Mime.const_defined?(const_name)
|
25
|
+
unless mime_constant = Mime[symbol]
|
29
26
|
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
|
30
27
|
"http://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
|
31
28
|
"If you meant to respond to a variant like :tablet or :phone, not a custom format, " \
|
@@ -33,8 +30,6 @@ module AbstractController
|
|
33
30
|
"format.html { |html| html.tablet { ... } }"
|
34
31
|
end
|
35
32
|
|
36
|
-
mime_constant = Mime.const_get(const_name)
|
37
|
-
|
38
33
|
if Mime::SET.include?(mime_constant)
|
39
34
|
AbstractController::Collector.generate_method_for_mime(mime_constant)
|
40
35
|
send(symbol, &block)
|
@@ -181,10 +181,10 @@ module AbstractController
|
|
181
181
|
end
|
182
182
|
|
183
183
|
def default_helper_module!
|
184
|
-
module_name = name.sub(/Controller$/, '')
|
184
|
+
module_name = name.sub(/Controller$/, ''.freeze)
|
185
185
|
module_path = module_name.underscore
|
186
186
|
helper module_path
|
187
|
-
rescue
|
187
|
+
rescue LoadError => e
|
188
188
|
raise e unless e.is_missing? "helpers/#{module_path}_helper"
|
189
189
|
rescue NameError => e
|
190
190
|
raise e unless e.missing_name? "#{module_name}Helper"
|
@@ -6,9 +6,9 @@ module AbstractController
|
|
6
6
|
define_method(:inherited) do |klass|
|
7
7
|
super(klass)
|
8
8
|
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
|
9
|
-
klass.
|
9
|
+
klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
|
10
10
|
else
|
11
|
-
klass.
|
11
|
+
klass.include(routes.url_helpers(include_path_helpers))
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -17,24 +17,28 @@ module AbstractController
|
|
17
17
|
extend ActiveSupport::Concern
|
18
18
|
include ActionView::ViewPaths
|
19
19
|
|
20
|
-
#
|
21
|
-
# sticks the result in self.response_body
|
20
|
+
# Normalizes arguments, options and then delegates render_to_body and
|
21
|
+
# sticks the result in <tt>self.response_body</tt>.
|
22
22
|
# :api: public
|
23
23
|
def render(*args, &block)
|
24
24
|
options = _normalize_render(*args, &block)
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
rendered_body = render_to_body(options)
|
26
|
+
if options[:html]
|
27
|
+
_set_html_content_type
|
28
|
+
else
|
29
|
+
_set_rendered_content_type rendered_format
|
30
|
+
end
|
31
|
+
self.response_body = rendered_body
|
28
32
|
end
|
29
33
|
|
30
34
|
# Raw rendering of a template to a string.
|
31
35
|
#
|
32
36
|
# It is similar to render, except that it does not
|
33
|
-
# set the response_body and it should be guaranteed
|
37
|
+
# set the +response_body+ and it should be guaranteed
|
34
38
|
# to always return a string.
|
35
39
|
#
|
36
|
-
# If a component extends the semantics of response_body
|
37
|
-
# (as
|
40
|
+
# If a component extends the semantics of +response_body+
|
41
|
+
# (as ActionController extends it to be anything that
|
38
42
|
# responds to the method each), this method needs to be
|
39
43
|
# overridden in order to still return a string.
|
40
44
|
# :api: plugin
|
@@ -51,14 +55,14 @@ module AbstractController
|
|
51
55
|
# Returns Content-Type of rendered content
|
52
56
|
# :api: public
|
53
57
|
def rendered_format
|
54
|
-
Mime
|
58
|
+
Mime[:text]
|
55
59
|
end
|
56
60
|
|
57
|
-
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %
|
61
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
|
58
62
|
@_action_name @_response_body @_formats @_prefixes @_config
|
59
63
|
@_view_context_class @_view_renderer @_lookup_context
|
60
64
|
@_routes @_db_runtime
|
61
|
-
)
|
65
|
+
)
|
62
66
|
|
63
67
|
# This method should return a hash with assigns.
|
64
68
|
# You can overwrite this configuration per controller.
|
@@ -73,17 +77,12 @@ module AbstractController
|
|
73
77
|
}
|
74
78
|
end
|
75
79
|
|
76
|
-
# Normalize args by converting render "foo" to
|
77
|
-
# render "foo
|
80
|
+
# Normalize args by converting <tt>render "foo"</tt> to
|
81
|
+
# <tt>render :action => "foo"</tt> and <tt>render "foo/bar"</tt> to
|
82
|
+
# <tt>render :file => "foo/bar"</tt>.
|
78
83
|
# :api: plugin
|
79
84
|
def _normalize_args(action=nil, options={})
|
80
|
-
if action.
|
81
|
-
if action.permitted?
|
82
|
-
action
|
83
|
-
else
|
84
|
-
raise ArgumentError, "render parameters are not permitted"
|
85
|
-
end
|
86
|
-
elsif action.is_a?(Hash)
|
85
|
+
if action.is_a? Hash
|
87
86
|
action
|
88
87
|
else
|
89
88
|
options
|
@@ -104,7 +103,13 @@ module AbstractController
|
|
104
103
|
|
105
104
|
# Process the rendered format.
|
106
105
|
# :api: private
|
107
|
-
def _process_format(format
|
106
|
+
def _process_format(format)
|
107
|
+
end
|
108
|
+
|
109
|
+
def _set_html_content_type # :nodoc:
|
110
|
+
end
|
111
|
+
|
112
|
+
def _set_rendered_content_type(format) # :nodoc:
|
108
113
|
end
|
109
114
|
|
110
115
|
# Normalize args and options.
|
@@ -112,7 +117,7 @@ module AbstractController
|
|
112
117
|
def _normalize_render(*args, &block)
|
113
118
|
options = _normalize_args(*args, &block)
|
114
119
|
#TODO: remove defined? when we restore AP <=> AV dependency
|
115
|
-
if defined?(request) && request
|
120
|
+
if defined?(request) && request.variant.present?
|
116
121
|
options[:variant] = request.variant
|
117
122
|
end
|
118
123
|
_normalize_options(options)
|
@@ -8,14 +8,15 @@ module AbstractController
|
|
8
8
|
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
9
9
|
# to translate many keys within the same controller / action and gives you a
|
10
10
|
# simple framework for scoping them consistently.
|
11
|
-
def translate(
|
12
|
-
key
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def translate(key, options = {})
|
12
|
+
if key.to_s.first == '.'
|
13
|
+
path = controller_path.tr('/', '.')
|
14
|
+
defaults = [:"#{path}#{key}"]
|
15
|
+
defaults << options[:default] if options[:default]
|
16
|
+
options[:default] = defaults
|
17
|
+
key = "#{path}.#{action_name}#{key}"
|
16
18
|
end
|
17
|
-
|
18
|
-
I18n.translate(*args)
|
19
|
+
I18n.translate(key, options)
|
19
20
|
end
|
20
21
|
alias :t :translate
|
21
22
|
|