actionpack 3.1.12 → 3.2.0.rc1
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.md +5503 -108
- data/README.rdoc +3 -3
- data/lib/abstract_controller/asset_paths.rb +1 -1
- data/lib/abstract_controller/base.rb +1 -1
- data/lib/abstract_controller/callbacks.rb +102 -18
- data/lib/abstract_controller/helpers.rb +1 -1
- data/lib/abstract_controller/layouts.rb +116 -50
- data/lib/abstract_controller/logger.rb +1 -1
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -2
- data/lib/abstract_controller/rendering.rb +1 -6
- data/lib/abstract_controller/view_paths.rb +6 -5
- data/lib/action_controller.rb +0 -15
- data/lib/action_controller/caching.rb +0 -1
- data/lib/action_controller/caching/actions.rb +5 -6
- data/lib/action_controller/caching/fragments.rb +18 -18
- data/lib/action_controller/caching/pages.rb +7 -6
- data/lib/action_controller/caching/sweeping.rb +1 -1
- data/lib/action_controller/log_subscriber.rb +8 -4
- data/lib/action_controller/metal.rb +7 -1
- data/lib/action_controller/metal/conditional_get.rb +49 -4
- data/lib/action_controller/metal/data_streaming.rb +17 -5
- data/lib/action_controller/metal/force_ssl.rb +8 -5
- data/lib/action_controller/metal/helpers.rb +7 -4
- data/lib/action_controller/metal/http_authentication.rb +9 -12
- data/lib/action_controller/metal/instrumentation.rb +9 -4
- data/lib/action_controller/metal/mime_responds.rb +4 -4
- data/lib/action_controller/metal/params_wrapper.rb +12 -8
- data/lib/action_controller/metal/redirecting.rb +7 -6
- data/lib/action_controller/metal/renderers.rb +9 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +2 -1
- data/lib/action_controller/metal/rescue.rb +13 -0
- data/lib/action_controller/metal/responder.rb +11 -23
- data/lib/action_controller/metal/streaming.rb +0 -25
- data/lib/action_controller/railtie.rb +1 -0
- data/lib/action_controller/railties/paths.rb +4 -3
- data/lib/action_controller/record_identifier.rb +4 -4
- data/lib/action_controller/test_case.rb +60 -56
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +6 -6
- data/lib/action_dispatch.rb +5 -1
- data/lib/action_dispatch/http/cache.rb +27 -15
- data/lib/action_dispatch/http/filter_parameters.rb +3 -1
- data/lib/action_dispatch/http/headers.rb +3 -5
- data/lib/action_dispatch/http/mime_negotiation.rb +2 -1
- data/lib/action_dispatch/http/mime_type.rb +7 -3
- data/lib/action_dispatch/http/mime_types.rb +12 -0
- data/lib/action_dispatch/http/parameter_filter.rb +3 -1
- data/lib/action_dispatch/http/parameters.rb +0 -4
- data/lib/action_dispatch/http/request.rb +18 -68
- data/lib/action_dispatch/http/response.rb +11 -32
- data/lib/action_dispatch/http/upload.rb +3 -14
- data/lib/action_dispatch/http/url.rb +1 -1
- data/lib/action_dispatch/middleware/callbacks.rb +1 -2
- data/lib/action_dispatch/middleware/cookies.rb +20 -16
- data/lib/action_dispatch/middleware/debug_exceptions.rb +82 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +78 -0
- data/lib/action_dispatch/middleware/flash.rb +6 -9
- data/lib/action_dispatch/middleware/params_parser.rb +6 -11
- data/lib/action_dispatch/middleware/public_exceptions.rb +30 -0
- data/lib/action_dispatch/middleware/reloader.rb +38 -14
- data/lib/action_dispatch/middleware/remote_ip.rb +66 -36
- data/lib/action_dispatch/middleware/request_id.rb +39 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +4 -16
- data/lib/action_dispatch/middleware/session/cache_store.rb +50 -0
- data/lib/action_dispatch/middleware/session/cookie_store.rb +1 -1
- data/lib/action_dispatch/middleware/show_exceptions.rb +58 -142
- data/lib/action_dispatch/middleware/static.rb +2 -10
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +13 -8
- data/lib/action_dispatch/railtie.rb +15 -1
- data/lib/action_dispatch/routing.rb +1 -2
- data/lib/action_dispatch/routing/mapper.rb +108 -107
- data/lib/action_dispatch/routing/redirection.rb +63 -69
- data/lib/action_dispatch/routing/route_set.rb +75 -43
- data/lib/action_dispatch/routing/routes_proxy.rb +0 -4
- data/lib/action_dispatch/routing/url_for.rb +3 -3
- data/lib/action_dispatch/testing/assertions/response.rb +5 -7
- data/lib/action_dispatch/testing/assertions/routing.rb +10 -9
- data/lib/action_dispatch/testing/integration.rb +8 -25
- data/lib/action_dispatch/testing/test_process.rb +3 -2
- data/lib/action_dispatch/testing/test_request.rb +4 -23
- data/lib/action_pack/version.rb +3 -3
- data/lib/action_view.rb +1 -5
- data/lib/action_view/asset_paths.rb +7 -8
- data/lib/action_view/base.rb +7 -5
- data/lib/action_view/helpers/asset_paths.rb +1 -1
- data/lib/action_view/helpers/asset_tag_helper.rb +4 -8
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +3 -0
- data/lib/action_view/helpers/atom_feed_helper.rb +2 -2
- data/lib/action_view/helpers/capture_helper.rb +3 -3
- data/lib/action_view/helpers/controller_helper.rb +1 -1
- data/lib/action_view/helpers/date_helper.rb +26 -18
- data/lib/action_view/helpers/debug_helper.rb +1 -1
- data/lib/action_view/helpers/form_helper.rb +71 -13
- data/lib/action_view/helpers/form_options_helper.rb +65 -34
- data/lib/action_view/helpers/form_tag_helper.rb +24 -18
- data/lib/action_view/helpers/javascript_helper.rb +12 -3
- data/lib/action_view/helpers/number_helper.rb +3 -2
- data/lib/action_view/helpers/record_tag_helper.rb +51 -5
- data/lib/action_view/helpers/rendering_helper.rb +2 -2
- data/lib/action_view/helpers/sanitize_helper.rb +6 -7
- data/lib/action_view/helpers/tag_helper.rb +1 -1
- data/lib/action_view/helpers/text_helper.rb +5 -4
- data/lib/action_view/helpers/url_helper.rb +19 -11
- data/lib/action_view/locale/en.yml +6 -0
- data/lib/action_view/log_subscriber.rb +1 -1
- data/lib/action_view/lookup_context.rb +123 -125
- data/lib/action_view/path_set.rb +60 -13
- data/lib/action_view/renderer/abstract_renderer.rb +16 -11
- data/lib/action_view/renderer/partial_renderer.rb +59 -40
- data/lib/action_view/renderer/template_renderer.rb +29 -17
- data/lib/action_view/template.rb +0 -1
- data/lib/action_view/template/error.rb +6 -5
- data/lib/action_view/template/handlers.rb +0 -6
- data/lib/action_view/template/handlers/builder.rb +10 -1
- data/lib/action_view/template/handlers/erb.rb +2 -2
- data/lib/action_view/template/resolver.rb +20 -31
- data/lib/action_view/test_case.rb +7 -10
- data/lib/sprockets/assets.rake +1 -1
- data/lib/sprockets/bootstrap.rb +3 -31
- data/lib/sprockets/compressors.rb +69 -7
- data/lib/sprockets/helpers/rails_helper.rb +6 -11
- data/lib/sprockets/railtie.rb +1 -0
- data/lib/sprockets/static_compiler.rb +0 -3
- metadata +57 -86
- checksums.yaml +0 -7
- data/lib/action_dispatch/middleware/closed_error.rb +0 -7
- data/lib/action_dispatch/routing/route.rb +0 -67
- data/lib/action_view/template/handler.rb +0 -49
@@ -7,9 +7,12 @@ module ActionController
|
|
7
7
|
# by default.
|
8
8
|
#
|
9
9
|
# In addition to using the standard template helpers provided, creating custom helpers to
|
10
|
-
# extract complicated logic or reusable functionality is strongly encouraged. By default,
|
11
|
-
# include
|
12
|
-
#
|
10
|
+
# extract complicated logic or reusable functionality is strongly encouraged. By default, each controller
|
11
|
+
# will include all helpers.
|
12
|
+
#
|
13
|
+
# In previous versions of \Rails the controller will include a helper whose
|
14
|
+
# name matches that of the controller, e.g., <tt>MyController</tt> will automatically
|
15
|
+
# include <tt>MyHelper</tt>. To return old behavior set +config.action_controller.include_all_helpers+ to +false+.
|
13
16
|
#
|
14
17
|
# Additional helpers can be specified using the +helper+ class method in ActionController::Base or any
|
15
18
|
# controller which inherits from it.
|
@@ -29,7 +32,7 @@ module ActionController
|
|
29
32
|
# class EventsController < ActionController::Base
|
30
33
|
# helper FormattedTimeHelper
|
31
34
|
# def index
|
32
|
-
# @events = Event.
|
35
|
+
# @events = Event.all
|
33
36
|
# end
|
34
37
|
# end
|
35
38
|
#
|
@@ -192,15 +192,12 @@ module ActionController
|
|
192
192
|
return false unless password
|
193
193
|
|
194
194
|
method = request.env['rack.methodoverride.original_method'] || request.env['REQUEST_METHOD']
|
195
|
-
uri = credentials[:uri][0,1] == '/' ? request.
|
195
|
+
uri = credentials[:uri][0,1] == '/' ? request.fullpath : request.url
|
196
196
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
expected == credentials[:response]
|
202
|
-
end
|
203
|
-
end
|
197
|
+
[true, false].any? do |password_is_ha1|
|
198
|
+
expected = expected_response(method, uri, credentials, password, password_is_ha1)
|
199
|
+
expected == credentials[:response]
|
200
|
+
end
|
204
201
|
end
|
205
202
|
end
|
206
203
|
|
@@ -227,9 +224,9 @@ module ActionController
|
|
227
224
|
end
|
228
225
|
|
229
226
|
def decode_credentials(header)
|
230
|
-
|
227
|
+
Hash[header.to_s.gsub(/^Digest\s+/,'').split(',').map do |pair|
|
231
228
|
key, value = pair.split('=', 2)
|
232
|
-
[key.strip, value.to_s.gsub(/^"|"$/,'').
|
229
|
+
[key.strip.to_sym, value.to_s.gsub(/^"|"$/,'').gsub(/'/, '')]
|
233
230
|
end]
|
234
231
|
end
|
235
232
|
|
@@ -403,7 +400,7 @@ module ActionController
|
|
403
400
|
# the present token and options.
|
404
401
|
#
|
405
402
|
# controller - ActionController::Base instance for the current request.
|
406
|
-
# login_procedure - Proc to call if a token is present.
|
403
|
+
# login_procedure - Proc to call if a token is present. The Proc should
|
407
404
|
# take 2 arguments:
|
408
405
|
# authenticate(controller) { |token, options| ... }
|
409
406
|
#
|
@@ -416,7 +413,7 @@ module ActionController
|
|
416
413
|
end
|
417
414
|
end
|
418
415
|
|
419
|
-
# Parses the token and options out of the token authorization header.
|
416
|
+
# Parses the token and options out of the token authorization header. If
|
420
417
|
# the header looks like this:
|
421
418
|
# Authorization: Token token="abc", nonce="def"
|
422
419
|
# Then the returned token is "abc", and the options is {:nonce => "def"}
|
@@ -58,13 +58,18 @@ module ActionController
|
|
58
58
|
def redirect_to(*args)
|
59
59
|
ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload|
|
60
60
|
result = super
|
61
|
-
payload[:status] =
|
62
|
-
payload[:location] =
|
61
|
+
payload[:status] = response.status
|
62
|
+
payload[:location] = response.location
|
63
63
|
result
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
private
|
68
|
+
|
69
|
+
# A hook invoked everytime a before callback is halted.
|
70
|
+
def halted_callback_hook(filter)
|
71
|
+
ActiveSupport::Notifications.instrument("halted_callback.action_controller", :filter => filter)
|
72
|
+
end
|
68
73
|
|
69
74
|
# A hook which allows you to clean up any time taken into account in
|
70
75
|
# views wrongly, like database querying time.
|
@@ -97,4 +102,4 @@ module ActionController
|
|
97
102
|
end
|
98
103
|
end
|
99
104
|
end
|
100
|
-
end
|
105
|
+
end
|
@@ -42,8 +42,8 @@ module ActionController #:nodoc:
|
|
42
42
|
def respond_to(*mimes)
|
43
43
|
options = mimes.extract_options!
|
44
44
|
|
45
|
-
only_actions = Array(options.delete(:only))
|
46
|
-
except_actions = Array(options.delete(:except))
|
45
|
+
only_actions = Array(options.delete(:only)).map(&:to_s)
|
46
|
+
except_actions = Array(options.delete(:except)).map(&:to_s)
|
47
47
|
|
48
48
|
new = mimes_for_respond_to.dup
|
49
49
|
mimes.each do |mime|
|
@@ -182,7 +182,7 @@ module ActionController #:nodoc:
|
|
182
182
|
#
|
183
183
|
# def index
|
184
184
|
# @people = Person.all
|
185
|
-
# respond_with(@
|
185
|
+
# respond_with(@people)
|
186
186
|
# end
|
187
187
|
# end
|
188
188
|
#
|
@@ -245,7 +245,7 @@ module ActionController #:nodoc:
|
|
245
245
|
# current action.
|
246
246
|
#
|
247
247
|
def collect_mimes_from_class_level #:nodoc:
|
248
|
-
action = action_name.
|
248
|
+
action = action_name.to_s
|
249
249
|
|
250
250
|
self.class.mimes_for_respond_to.keys.select do |mime|
|
251
251
|
config = self.class.mimes_for_respond_to[mime]
|
@@ -43,6 +43,11 @@ module ActionController
|
|
43
43
|
# wrap_parameters :person, :include => [:username, :password]
|
44
44
|
# end
|
45
45
|
#
|
46
|
+
# On ActiveRecord models with no +:include+ or +:exclude+ option set,
|
47
|
+
# if attr_accessible is set on that model, it will only wrap the accessible
|
48
|
+
# parameters, else it will only wrap the parameters returned by the class
|
49
|
+
# method attribute_names.
|
50
|
+
#
|
46
51
|
# If you're going to pass the parameters to an +ActiveModel+ object (such as
|
47
52
|
# +User.new(params[:user])+), you might consider passing the model class to
|
48
53
|
# the method instead. The +ParamsWrapper+ will actually try to determine the
|
@@ -141,19 +146,16 @@ module ActionController
|
|
141
146
|
# try to find Foo::Bar::User, Foo::User and finally User.
|
142
147
|
def _default_wrap_model #:nodoc:
|
143
148
|
return nil if self.anonymous?
|
144
|
-
|
145
|
-
model_name = self.name.sub(/Controller$/, '').singularize
|
149
|
+
model_name = self.name.sub(/Controller$/, '').classify
|
146
150
|
|
147
151
|
begin
|
148
|
-
model_klass = model_name.
|
149
|
-
|
150
|
-
|
152
|
+
if model_klass = model_name.safe_constantize
|
153
|
+
model_klass
|
154
|
+
else
|
151
155
|
namespaces = model_name.split("::")
|
152
156
|
namespaces.delete_at(-2)
|
153
157
|
break if namespaces.last == model_name
|
154
158
|
model_name = namespaces.join("::")
|
155
|
-
else
|
156
|
-
raise
|
157
159
|
end
|
158
160
|
end until model_klass
|
159
161
|
|
@@ -165,7 +167,9 @@ module ActionController
|
|
165
167
|
|
166
168
|
unless options[:include] || options[:exclude]
|
167
169
|
model ||= _default_wrap_model
|
168
|
-
if model.respond_to?(:
|
170
|
+
if model.respond_to?(:accessible_attributes) && model.accessible_attributes.present?
|
171
|
+
options[:include] = model.accessible_attributes.to_a
|
172
|
+
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
|
169
173
|
options[:include] = model.attribute_names
|
170
174
|
end
|
171
175
|
end
|
@@ -18,7 +18,7 @@ module ActionController
|
|
18
18
|
#
|
19
19
|
# * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
|
20
20
|
# * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
|
21
|
-
# * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) - Is passed straight through as the target for redirection.
|
21
|
+
# * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) or a protocol relative reference (like <tt>//</tt>) - Is passed straight through as the target for redirection.
|
22
22
|
# * <tt>String</tt> not containing a protocol - The current protocol and host is prepended to the string.
|
23
23
|
# * <tt>Proc</tt> - A block that will be executed in the controller's context. Should return any option accepted by +redirect_to+.
|
24
24
|
# * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
|
@@ -54,10 +54,10 @@ module ActionController
|
|
54
54
|
# redirect_to post_url(@post), :status => 301, :flash => { :updated_post_id => @post.id }
|
55
55
|
# redirect_to { :action=>'atom' }, :alert => "Something serious happened"
|
56
56
|
#
|
57
|
-
# When using <tt>redirect_to :back</tt>, if there is no referrer, RedirectBackError will be raised. You may specify some fallback
|
58
|
-
# behavior for this case by rescuing RedirectBackError.
|
57
|
+
# When using <tt>redirect_to :back</tt>, if there is no referrer, ActionController::RedirectBackError will be raised. You may specify some fallback
|
58
|
+
# behavior for this case by rescuing ActionController::RedirectBackError.
|
59
59
|
def redirect_to(options = {}, response_status = {}) #:doc:
|
60
|
-
raise ActionControllerError.new("Cannot redirect to nil!")
|
60
|
+
raise ActionControllerError.new("Cannot redirect to nil!") unless options
|
61
61
|
raise AbstractController::DoubleRenderError if response_body
|
62
62
|
|
63
63
|
self.status = _extract_redirect_to_status(options, response_status)
|
@@ -81,7 +81,8 @@ module ActionController
|
|
81
81
|
# The scheme name consist of a letter followed by any combination of
|
82
82
|
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
|
83
83
|
# characters; and is terminated by a colon (":").
|
84
|
-
|
84
|
+
# The protocol relative scheme starts with a double slash "//"
|
85
|
+
when %r{^(\w[\w+.-]*:|//).*}
|
85
86
|
options
|
86
87
|
when String
|
87
88
|
request.protocol + request.host_with_port + options
|
@@ -92,7 +93,7 @@ module ActionController
|
|
92
93
|
_compute_redirect_to_location options.call
|
93
94
|
else
|
94
95
|
url_for(options)
|
95
|
-
end.gsub(/[\
|
96
|
+
end.gsub(/[\r\n]/, '')
|
96
97
|
end
|
97
98
|
end
|
98
99
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute'
|
2
2
|
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'set'
|
3
4
|
|
4
5
|
module ActionController
|
5
6
|
# See <tt>Renderers.add</tt>
|
@@ -12,16 +13,13 @@ module ActionController
|
|
12
13
|
|
13
14
|
included do
|
14
15
|
class_attribute :_renderers
|
15
|
-
self._renderers =
|
16
|
+
self._renderers = Set.new.freeze
|
16
17
|
end
|
17
18
|
|
18
19
|
module ClassMethods
|
19
20
|
def use_renderers(*args)
|
20
|
-
|
21
|
-
|
22
|
-
new[key] = RENDERERS[key]
|
23
|
-
end
|
24
|
-
self._renderers = new.freeze
|
21
|
+
renderers = _renderers + args
|
22
|
+
self._renderers = renderers.freeze
|
25
23
|
end
|
26
24
|
alias use_renderer use_renderers
|
27
25
|
end
|
@@ -31,10 +29,10 @@ module ActionController
|
|
31
29
|
end
|
32
30
|
|
33
31
|
def _handle_render_options(options)
|
34
|
-
_renderers.each do |name
|
35
|
-
if options.key?(name
|
32
|
+
_renderers.each do |name|
|
33
|
+
if options.key?(name)
|
36
34
|
_process_options(options)
|
37
|
-
return send("_render_option_#{name}", options.delete(name
|
35
|
+
return send("_render_option_#{name}", options.delete(name), options)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
nil
|
@@ -42,7 +40,7 @@ module ActionController
|
|
42
40
|
|
43
41
|
# Hash of available renderers, mapping a renderer name to its proc.
|
44
42
|
# Default keys are :json, :js, :xml.
|
45
|
-
RENDERERS =
|
43
|
+
RENDERERS = Set.new
|
46
44
|
|
47
45
|
# Adds a new renderer to call within controller actions.
|
48
46
|
# A renderer is invoked by passing its name as an option to
|
@@ -79,7 +77,7 @@ module ActionController
|
|
79
77
|
# <tt>ActionController::MimeResponds#respond_with</tt>
|
80
78
|
def self.add(key, &block)
|
81
79
|
define_method("_render_option_#{key}", &block)
|
82
|
-
RENDERERS
|
80
|
+
RENDERERS << key.to_sym
|
83
81
|
end
|
84
82
|
|
85
83
|
module All
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/class/attribute'
|
2
|
+
require 'action_controller/metal/exceptions'
|
2
3
|
|
3
4
|
module ActionController #:nodoc:
|
4
5
|
class InvalidAuthenticityToken < ActionControllerError #:nodoc:
|
@@ -73,7 +74,7 @@ module ActionController #:nodoc:
|
|
73
74
|
# The actual before_filter that is used. Modify this to change how you handle unverified requests.
|
74
75
|
def verify_authenticity_token
|
75
76
|
unless verified_request?
|
76
|
-
logger.
|
77
|
+
logger.warn "WARNING: Can't verify CSRF token authenticity" if logger
|
77
78
|
handle_unverified_request
|
78
79
|
end
|
79
80
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
module ActionController #:nodoc:
|
2
|
+
# This module is responsible to provide `rescue_from` helpers
|
3
|
+
# to controllers and configure when detailed exceptions must be
|
4
|
+
# shown.
|
2
5
|
module Rescue
|
3
6
|
extend ActiveSupport::Concern
|
4
7
|
include ActiveSupport::Rescuable
|
@@ -12,10 +15,20 @@ module ActionController #:nodoc:
|
|
12
15
|
super(exception)
|
13
16
|
end
|
14
17
|
|
18
|
+
# Override this method if you want to customize when detailed
|
19
|
+
# exceptions must be shown. This method is only called when
|
20
|
+
# consider_all_requests_local is false. By default, it returns
|
21
|
+
# false, but someone may set it to `request.local?` so local
|
22
|
+
# requests in production still shows the detailed exception pages.
|
23
|
+
def show_detailed_exceptions?
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
15
27
|
private
|
16
28
|
def process_action(*args)
|
17
29
|
super
|
18
30
|
rescue Exception => exception
|
31
|
+
request.env['action_dispatch.show_detailed_exceptions'] ||= show_detailed_exceptions?
|
19
32
|
rescue_with_handler(exception) || raise(exception)
|
20
33
|
end
|
21
34
|
end
|
@@ -9,7 +9,7 @@ module ActionController #:nodoc:
|
|
9
9
|
# respond_to :html, :xml, :json
|
10
10
|
#
|
11
11
|
# def index
|
12
|
-
# @people = Person.
|
12
|
+
# @people = Person.all
|
13
13
|
# respond_with(@people)
|
14
14
|
# end
|
15
15
|
# end
|
@@ -84,8 +84,8 @@ module ActionController #:nodoc:
|
|
84
84
|
#
|
85
85
|
# === Custom options
|
86
86
|
#
|
87
|
-
# <code>respond_with</code> also
|
88
|
-
# to the underlying render call. Those options are only applied success
|
87
|
+
# <code>respond_with</code> also allows you to pass options that are forwarded
|
88
|
+
# to the underlying render call. Those options are only applied for success
|
89
89
|
# scenarios. For instance, you can do the following in the create method above:
|
90
90
|
#
|
91
91
|
# def create
|
@@ -95,7 +95,7 @@ module ActionController #:nodoc:
|
|
95
95
|
# respond_with(@project, @task, :status => 201)
|
96
96
|
# end
|
97
97
|
#
|
98
|
-
# This will return status 201 if the task was saved
|
98
|
+
# This will return status 201 if the task was saved successfully. If not,
|
99
99
|
# it will simply ignore the given options and return status 422 and the
|
100
100
|
# resource errors. To customize the failure scenario, you can pass a
|
101
101
|
# a block to <code>respond_with</code>:
|
@@ -202,10 +202,8 @@ module ActionController #:nodoc:
|
|
202
202
|
display resource
|
203
203
|
elsif post?
|
204
204
|
display resource, :status => :created, :location => api_location
|
205
|
-
elsif has_empty_resource_definition?
|
206
|
-
display empty_resource, :status => :ok
|
207
205
|
else
|
208
|
-
head :
|
206
|
+
head :no_content
|
209
207
|
end
|
210
208
|
end
|
211
209
|
|
@@ -224,7 +222,7 @@ module ActionController #:nodoc:
|
|
224
222
|
alias :navigation_location :resource_location
|
225
223
|
alias :api_location :resource_location
|
226
224
|
|
227
|
-
# If a
|
225
|
+
# If a response block was given, use it, otherwise call render on
|
228
226
|
# controller.
|
229
227
|
#
|
230
228
|
def default_render
|
@@ -253,7 +251,7 @@ module ActionController #:nodoc:
|
|
253
251
|
end
|
254
252
|
|
255
253
|
def display_errors
|
256
|
-
controller.render format =>
|
254
|
+
controller.render format => resource_errors, :status => :unprocessable_entity
|
257
255
|
end
|
258
256
|
|
259
257
|
# Check whether the resource has errors.
|
@@ -269,22 +267,12 @@ module ActionController #:nodoc:
|
|
269
267
|
@action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
|
270
268
|
end
|
271
269
|
|
272
|
-
|
273
|
-
|
274
|
-
def has_empty_resource_definition?
|
275
|
-
respond_to?("empty_#{format}_resource", true)
|
270
|
+
def resource_errors
|
271
|
+
respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors
|
276
272
|
end
|
277
273
|
|
278
|
-
|
279
|
-
|
280
|
-
def empty_resource
|
281
|
-
send("empty_#{format}_resource")
|
282
|
-
end
|
283
|
-
|
284
|
-
# Return a valid empty JSON resource
|
285
|
-
#
|
286
|
-
def empty_json_resource
|
287
|
-
"{}"
|
274
|
+
def json_resource_errors
|
275
|
+
{:errors => resource.errors}
|
288
276
|
end
|
289
277
|
end
|
290
278
|
end
|
@@ -200,34 +200,9 @@ module ActionController #:nodoc:
|
|
200
200
|
extend ActiveSupport::Concern
|
201
201
|
|
202
202
|
include AbstractController::Rendering
|
203
|
-
attr_internal :stream
|
204
|
-
|
205
|
-
module ClassMethods
|
206
|
-
# Render streaming templates. It accepts :only, :except, :if and :unless as options
|
207
|
-
# to specify when to stream, as in ActionController filters.
|
208
|
-
def stream(options={})
|
209
|
-
ActiveSupport::Deprecation.warn "stream class method is deprecated. Please give the :stream option to render instead"
|
210
|
-
if defined?(Fiber)
|
211
|
-
before_filter :_stream_filter, options
|
212
|
-
else
|
213
|
-
raise "You cannot use streaming if Fiber is not available."
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
203
|
|
218
204
|
protected
|
219
205
|
|
220
|
-
# Mark following render calls as streaming.
|
221
|
-
def _stream_filter #:nodoc:
|
222
|
-
self.stream = true
|
223
|
-
end
|
224
|
-
|
225
|
-
# Consider the stream option when normalazing options.
|
226
|
-
def _normalize_options(options) #:nodoc:
|
227
|
-
super
|
228
|
-
options[:stream] = self.stream unless options.key?(:stream)
|
229
|
-
end
|
230
|
-
|
231
206
|
# Set proper cache control and transfer encoding when streaming
|
232
207
|
def _process_options(options) #:nodoc:
|
233
208
|
super
|
@@ -29,6 +29,7 @@ module ActionController
|
|
29
29
|
# make sure readers methods get compiled
|
30
30
|
options.asset_path ||= app.config.asset_path
|
31
31
|
options.asset_host ||= app.config.asset_host
|
32
|
+
options.relative_url_root ||= app.config.relative_url_root
|
32
33
|
|
33
34
|
ActiveSupport.on_load(:action_controller) do
|
34
35
|
include app.routes.mounted_helpers
|