From 860202e8b2e3579402d48d7e56fa738a9529a340 Mon Sep 17 00:00:00 2001 From: thoefer Date: Mon, 1 Aug 2011 11:28:31 +0200 Subject: Fix the issue where default_url_options is being cached on test cases. Closes #1872. Closes #2031. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/metal/testing.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/testing.rb b/actionpack/lib/action_controller/metal/testing.rb index f4efeb33ba..d1813ee745 100644 --- a/actionpack/lib/action_controller/metal/testing.rb +++ b/actionpack/lib/action_controller/metal/testing.rb @@ -4,6 +4,11 @@ module ActionController include RackDelegation + def recycle! + @_url_options = nil + end + + # TODO: Clean this up def process_with_new_base_test(request, response) @_request = request -- cgit v1.2.3 From 8845ae683e2688bc619baade49510c17e978518f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 7 Aug 2011 12:34:49 -0300 Subject: x_sendfile_header now defaults to nil and production.rb env file doesn't set a particular value for it. This allows servers to set it through X-Sendfile-Type, read https://github.com/rack/rack/blob/master/lib/rack/sendfile.rb for more info. Anyways you can force this value in your production.rb --- actionpack/lib/action_controller/metal/data_streaming.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 0785fe9679..5e077dd7bd 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -17,7 +17,7 @@ module ActionController #:nodoc: protected # Sends the file. This uses a server-appropriate method (such as X-Sendfile) # via the Rack::Sendfile middleware. The header to use is set via - # config.action_dispatch.x_sendfile_header, and defaults to "X-Sendfile". + # config.action_dispatch.x_sendfile_header. # Your server can also configure this for you by setting the X-Sendfile-Type header. # # Be careful to sanitize the path parameter if it is coming from a web -- cgit v1.2.3 From 75dd33a0aed96d9f03b79c82f7e5bc5ccf462e8e Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Sun, 14 Aug 2011 18:58:29 +0200 Subject: Methods like status and location are interfering with redirect_to [Closes #2511] --- actionpack/lib/action_controller/metal/instrumentation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 85d0f5f699..777a0ab343 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -58,8 +58,8 @@ module ActionController def redirect_to(*args) ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload| result = super - payload[:status] = self.status - payload[:location] = self.location + payload[:status] = response.status + payload[:location] = response.location result end end @@ -97,4 +97,4 @@ module ActionController end end end -end \ No newline at end of file +end -- cgit v1.2.3 From 6c5f67cac15c43bafcd917c346cccfcf3fa5fb95 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 00:59:59 +0100 Subject: Don't refer to ActionController::Base in the wrap_parameters initializer - use config object instead. Cuts about 15% off the load time. (#734) --- actionpack/lib/action_controller/metal/params_wrapper.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 2d8afc3a78..dfc4e3d72c 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -121,6 +121,8 @@ module ActionController _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) end + alias :wrap_parameters= :wrap_parameters + # Sets the default wrapper key or model which will be used to determine # wrapper key and attribute names. Will be called automatically when the # module is inherited. -- cgit v1.2.3 From 8e236152457ed48bb436e9bffb4c5d6d4b6a26d4 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 16 Aug 2011 19:14:06 +0100 Subject: Use lazy load hooks to set parameter wrapping configuration. This means that it doesn't force Action Controller / Active Record to load, but it doesn't fail if they have already loaded. Thanks @josevalim for the hint. --- actionpack/lib/action_controller/metal/params_wrapper.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index dfc4e3d72c..2d8afc3a78 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -121,8 +121,6 @@ module ActionController _set_wrapper_defaults(_wrapper_options.slice(:format).merge(options), model) end - alias :wrap_parameters= :wrap_parameters - # Sets the default wrapper key or model which will be used to determine # wrapper key and attribute names. Will be called automatically when the # module is inherited. -- cgit v1.2.3 From 31d38d37d394f6ebbac57ce48f465805edbfec04 Mon Sep 17 00:00:00 2001 From: dharmatech Date: Sat, 20 Aug 2011 00:07:34 -0500 Subject: ActionController::Redirecting : fix docs typo --- actionpack/lib/action_controller/metal/redirecting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index dee7eb1ec8..4f311a1cf5 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -45,7 +45,7 @@ module ActionController # integer, or a symbol representing the downcased, underscored and symbolized description. # Note that the status code must be a 3xx HTTP code, or redirection will not occur. # - # It is also possible to assign a flash message as part of the redirection. There are two special accessors for commonly used the flash names + # It is also possible to assign a flash message as part of the redirection. There are two special accessors for the commonly used flash names # +alert+ and +notice+ as well as a general purpose +flash+ bucket. # # Examples: -- cgit v1.2.3 From 7da70a431c3c122d3b9425472635bf8368363525 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 20 Aug 2011 23:49:57 +0530 Subject: params wrapper docs correction --- actionpack/lib/action_controller/metal/params_wrapper.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 2d8afc3a78..f24203db3a 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -9,10 +9,9 @@ module ActionController # Wraps parameters hash into nested hash. This will allow client to submit # POST request without having to specify a root element in it. # - # By default this functionality won't be enabled. You can enable - # it globally by setting +ActionController::Base.wrap_parameters+: - # - # ActionController::Base.wrap_parameters = [:json] + # This functionality is enabled in +config/initializers/wrap_parameters.rb+ + # and can be customized. If you are upgrading to Rails 3.1, this file will + # need to be created for the functionality to be enabled. # # You could also turn it on per controller by setting the format array to # non-empty array: -- cgit v1.2.3 From 8526f727cfadb49e629e7ac3a0bbcbf9a89ec3cd Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 28 Aug 2011 02:25:54 +0530 Subject: doc fixes --- actionpack/lib/action_controller/metal/params_wrapper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index f24203db3a..6acbb23907 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -6,30 +6,30 @@ require 'active_support/core_ext/module/anonymous' require 'action_dispatch/http/mime_types' module ActionController - # Wraps parameters hash into nested hash. This will allow client to submit - # POST request without having to specify a root element in it. + # Wraps the parameters hash into a nested hash. This will allow clients to submit + # POST requests without having to specify any root elements. # # This functionality is enabled in +config/initializers/wrap_parameters.rb+ - # and can be customized. If you are upgrading to Rails 3.1, this file will + # and can be customized. If you are upgrading to \Rails 3.1, this file will # need to be created for the functionality to be enabled. # # You could also turn it on per controller by setting the format array to - # non-empty array: + # a non-empty array: # # class UsersController < ApplicationController # wrap_parameters :format => [:json, :xml] # end # - # If you enable +ParamsWrapper+ for +:json+ format. Instead of having to + # If you enable +ParamsWrapper+ for +:json+ format, instead of having to # send JSON parameters like this: # # {"user": {"name": "Konata"}} # - # You can now just send a parameters like this: + # You can send parameters like this: # # {"name": "Konata"} # - # And it will be wrapped into a nested hash with the key name matching + # And it will be wrapped into a nested hash with the key name matching the # controller's name. For example, if you're posting to +UsersController+, # your new +params+ hash will look like this: # @@ -81,7 +81,7 @@ module ActionController # # ==== Examples # wrap_parameters :format => :xml - # # enables the parmeter wrapper for XML format + # # enables the parameter wrapper for XML format # # wrap_parameters :person # # wraps parameters into +params[:person]+ hash -- cgit v1.2.3 From bb4dedbc2cc7b96b95bf4519f56ed9624949a7ef Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 27 Aug 2011 15:34:33 -0700 Subject: deletes spurious arrow --- actionpack/lib/action_controller/metal/url_for.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb index 08132b1900..0b40b1fc4c 100644 --- a/actionpack/lib/action_controller/metal/url_for.rb +++ b/actionpack/lib/action_controller/metal/url_for.rb @@ -18,7 +18,7 @@ # @url = root_path # named route from the application. # end # end -# => +# module ActionController module UrlFor extend ActiveSupport::Concern -- cgit v1.2.3 From 19ec3c1ae6d0e0b452a4b2d92b4840abb23f4035 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Sat, 3 Sep 2011 23:13:40 +0400 Subject: fix helpers behavior description --- actionpack/lib/action_controller/metal/helpers.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index 2df0e9422c..bd515bba82 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -7,9 +7,12 @@ module ActionController # by default. # # In addition to using the standard template helpers provided, creating custom helpers to - # extract complicated logic or reusable functionality is strongly encouraged. By default, the controller will - # include a helper whose name matches that of the controller, e.g., MyController will automatically - # include MyHelper. + # extract complicated logic or reusable functionality is strongly encouraged. By default, each controller + # will include all helpers. + # + # In previous versions of \Rails the controller will include a helper whose + # name matches that of the controller, e.g., MyController will automatically + # include MyHelper. To return old behavior set +config.action_controller.include_all_helpers+ to +false+. # # Additional helpers can be specified using the +helper+ class method in ActionController::Base or any # controller which inherits from it. -- cgit v1.2.3 From 9b08afd2f4d501fb1710ba0ed4e19313093605c8 Mon Sep 17 00:00:00 2001 From: Milan Dobrota Date: Sun, 4 Sep 2011 10:44:08 -0500 Subject: if ... nil? is more expensive than unless --- actionpack/lib/action_controller/metal/redirecting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 4f311a1cf5..f2dfb3833b 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -57,7 +57,7 @@ module ActionController # When using redirect_to :back, if there is no referrer, RedirectBackError will be raised. You may specify some fallback # behavior for this case by rescuing RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: - raise ActionControllerError.new("Cannot redirect to nil!") if options.nil? + raise ActionControllerError.new("Cannot redirect to nil!") unless options raise AbstractController::DoubleRenderError if response_body self.status = _extract_redirect_to_status(options, response_status) -- cgit v1.2.3 From f6ced69a11cdff56c2e87b84e775ef09c6d999d1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 Sep 2011 17:25:20 -0700 Subject: Eliminate newlines in basic auth. fixes #2882 --- actionpack/lib/action_controller/metal/http_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 7420a5e7e9..264806cd36 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -145,7 +145,7 @@ module ActionController end def encode_credentials(user_name, password) - "Basic #{ActiveSupport::Base64.encode64("#{user_name}:#{password}")}" + "Basic #{ActiveSupport::Base64.encode64s("#{user_name}:#{password}")}" end def authentication_request(controller, realm) -- cgit v1.2.3 From 7fb99e5743d88c04357e09960d112376428a6faa Mon Sep 17 00:00:00 2001 From: Mike Dillon Date: Fri, 2 Sep 2011 08:22:29 -0700 Subject: Change log level for CSRF token verification warning --- actionpack/lib/action_controller/metal/request_forgery_protection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index 4d016271ea..bc22e39efb 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -74,7 +74,7 @@ module ActionController #:nodoc: # The actual before_filter that is used. Modify this to change how you handle unverified requests. def verify_authenticity_token unless verified_request? - logger.debug "WARNING: Can't verify CSRF token authenticity" if logger + logger.warn "WARNING: Can't verify CSRF token authenticity" if logger handle_unverified_request end end -- cgit v1.2.3 From e8987c30d0dc3ae5903a6d3a6e293641759b6fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 23 Sep 2011 16:46:33 +0200 Subject: Use safe_constantize where possible. --- actionpack/lib/action_controller/metal/params_wrapper.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 6acbb23907..e0d8e1c992 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -141,19 +141,16 @@ module ActionController # try to find Foo::Bar::User, Foo::User and finally User. def _default_wrap_model #:nodoc: return nil if self.anonymous? - model_name = self.name.sub(/Controller$/, '').singularize begin - model_klass = model_name.constantize - rescue NameError, ArgumentError => e - if e.message =~ /is not missing constant|uninitialized constant #{model_name}/ + if model_klass = model_name.safe_constantize + model_klass + else namespaces = model_name.split("::") namespaces.delete_at(-2) break if namespaces.last == model_name model_name = namespaces.join("::") - else - raise end end until model_klass -- cgit v1.2.3 From d68f27e9b184a8e7e4ce71db11874a6b36ea1edc Mon Sep 17 00:00:00 2001 From: Ben Scheirman Date: Sat, 8 Oct 2011 18:38:02 -0500 Subject: accept optional :host parameter to force_ssl --- actionpack/lib/action_controller/metal/force_ssl.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb index ed693c5967..0fd42f9d8a 100644 --- a/actionpack/lib/action_controller/metal/force_ssl.rb +++ b/actionpack/lib/action_controller/metal/force_ssl.rb @@ -24,12 +24,15 @@ module ActionController # * only - The callback should be run only for this action # * except - The callback should be run for all actions except this action def force_ssl(options = {}) + host = options.delete(:host) before_filter(options) do if !request.ssl? && !Rails.env.development? - redirect_to :protocol => 'https://', :status => :moved_permanently + redirect_options = {:protocol => 'https://', :status => :moved_permanently} + redirect_options.merge!(:host => host) if host + redirect_to redirect_options end end end end end -end \ No newline at end of file +end -- cgit v1.2.3 From a0a68ecbb22dacf5111198e72e3a803e7c965881 Mon Sep 17 00:00:00 2001 From: Denis Odorcic Date: Mon, 10 Oct 2011 01:42:12 -0400 Subject: JSON responder should return errors with :error root --- actionpack/lib/action_controller/metal/responder.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index 3794e277f6..c7827309dd 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -253,7 +253,7 @@ module ActionController #:nodoc: end def display_errors - controller.render format => resource.errors, :status => :unprocessable_entity + controller.render format => resource_errors, :status => :unprocessable_entity end # Check whether the resource has errors. @@ -286,5 +286,13 @@ module ActionController #:nodoc: def empty_json_resource "{}" end + + def resource_errors + respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors + end + + def json_resource_errors + {:errors => resource.errors} + end end end -- cgit v1.2.3 From 419d4c09dfcc5cbd898ce52d779603c6a29ac3bc Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 11 Oct 2011 12:31:27 +0400 Subject: Add ActionController#head example --- actionpack/lib/action_controller/metal/head.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index 8abcad55a2..a618533d09 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -9,6 +9,8 @@ module ActionController # # head :created, :location => person_path(@person) # + # head :created, :location => @person + # # It can also be used to return exceptional conditions: # # return head(:method_not_allowed) unless request.post? -- cgit v1.2.3 From 50d262f52ab39680b031e485b89b64875c08358e Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 11 Oct 2011 12:48:03 +0400 Subject: Support symbol and string actions in AC#respond_to options --- actionpack/lib/action_controller/metal/mime_responds.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index f10287afb4..00bd1706e7 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -42,8 +42,8 @@ module ActionController #:nodoc: def respond_to(*mimes) options = mimes.extract_options! - only_actions = Array(options.delete(:only)) - except_actions = Array(options.delete(:except)) + only_actions = Array(options.delete(:only)).map(&:to_s) + except_actions = Array(options.delete(:except)).map(&:to_s) new = mimes_for_respond_to.dup mimes.each do |mime| @@ -245,7 +245,7 @@ module ActionController #:nodoc: # current action. # def collect_mimes_from_class_level #:nodoc: - action = action_name.to_sym + action = action_name.to_s self.class.mimes_for_respond_to.keys.select do |mime| config = self.class.mimes_for_respond_to[mime] -- cgit v1.2.3 From 4a025f0080d05f6c27518a84cde0b93fa3821345 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 12 Oct 2011 15:44:19 +0900 Subject: status is a number in Rails 3 --- actionpack/lib/action_controller/metal/data_streaming.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb index 5e077dd7bd..0670a58d97 100644 --- a/actionpack/lib/action_controller/metal/data_streaming.rb +++ b/actionpack/lib/action_controller/metal/data_streaming.rb @@ -34,7 +34,7 @@ module ActionController #:nodoc: # If no content type is registered for the extension, default type 'application/octet-stream' will be used. # * :disposition - specifies whether the file will be shown inline or downloaded. # Valid values are 'inline' and 'attachment' (default). - # * :status - specifies the status code to send with the response. Defaults to '200 OK'. + # * :status - specifies the status code to send with the response. Defaults to 200. # * :url_based_filename - set to +true+ if you want the browser guess the filename from # the URL, which is necessary for i18n filenames on certain browsers # (setting :filename overrides this option). @@ -92,7 +92,7 @@ module ActionController #:nodoc: # If no content type is registered for the extension, default type 'application/octet-stream' will be used. # * :disposition - specifies whether the file will be shown inline or downloaded. # Valid values are 'inline' and 'attachment' (default). - # * :status - specifies the status code to send with the response. Defaults to '200 OK'. + # * :status - specifies the status code to send with the response. Defaults to 200. # # Generic data download: # -- cgit v1.2.3 From 8ff7693a8dc61f43fc4eaf72ed24d3b8699191fe Mon Sep 17 00:00:00 2001 From: Jose and Yehuda Date: Mon, 26 Sep 2011 18:48:19 -0400 Subject: Initial commit of serializer support --- .../lib/action_controller/metal/serialization.rb | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 actionpack/lib/action_controller/metal/serialization.rb (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb new file mode 100644 index 0000000000..9bb665a9ae --- /dev/null +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -0,0 +1,26 @@ +module ActionController + module Serialization + extend ActiveSupport::Concern + + include ActionController::Renderers + + included do + class_attribute :_serialization_scope + end + + def serialization_scope + send(_serialization_scope) + end + + def _render_option_json(json, options) + json = json.active_model_serializer.new(json, serialization_scope) if json.respond_to?(:active_model_serializer) + super + end + + module ClassMethods + def serialization_scope(scope) + self._serialization_scope = scope + end + end + end +end -- cgit v1.2.3 From a4c04a43cc96d9c94b7a5ecd5c7458fdc2f8617f Mon Sep 17 00:00:00 2001 From: Jose and Yehuda Date: Mon, 26 Sep 2011 18:57:49 -0400 Subject: Refactor to make renderers a Set --- actionpack/lib/action_controller/metal/renderers.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 0ad9dbeda9..6e9ce450ac 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -1,5 +1,6 @@ require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/object/blank' +require 'set' module ActionController # See Renderers.add @@ -12,16 +13,13 @@ module ActionController included do class_attribute :_renderers - self._renderers = {}.freeze + self._renderers = Set.new.freeze end module ClassMethods def use_renderers(*args) - new = _renderers.dup - args.each do |key| - new[key] = RENDERERS[key] - end - self._renderers = new.freeze + renderers = _renderers + args + self._renderers = renderers.freeze end alias use_renderer use_renderers end @@ -31,10 +29,10 @@ module ActionController end def _handle_render_options(options) - _renderers.each do |name, value| - if options.key?(name.to_sym) + _renderers.each do |name| + if options.key?(name) _process_options(options) - return send("_render_option_#{name}", options.delete(name.to_sym), options) + return send("_render_option_#{name}", options.delete(name), options) end end nil @@ -42,7 +40,7 @@ module ActionController # Hash of available renderers, mapping a renderer name to its proc. # Default keys are :json, :js, :xml. - RENDERERS = {} + RENDERERS = Set.new # Adds a new renderer to call within controller actions. # A renderer is invoked by passing its name as an option to @@ -79,7 +77,7 @@ module ActionController # ActionController::MimeResponds#respond_with def self.add(key, &block) define_method("_render_option_#{key}", &block) - RENDERERS[key] = block + RENDERERS << key.to_sym end module All -- cgit v1.2.3 From a7641054d80a285c5da85d80b8678d899c27cd1a Mon Sep 17 00:00:00 2001 From: Nick Howard Date: Tue, 25 Oct 2011 10:39:20 -0600 Subject: add namespacing when referring to ActionController::RedirectBackError --- actionpack/lib/action_controller/metal/redirecting.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index f2dfb3833b..0355c9f458 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -54,8 +54,8 @@ module ActionController # redirect_to post_url(@post), :status => 301, :flash => { :updated_post_id => @post.id } # redirect_to { :action=>'atom' }, :alert => "Something serious happened" # - # When using redirect_to :back, if there is no referrer, RedirectBackError will be raised. You may specify some fallback - # behavior for this case by rescuing RedirectBackError. + # When using redirect_to :back, if there is no referrer, ActionController::RedirectBackError will be raised. You may specify some fallback + # behavior for this case by rescuing ActionController::RedirectBackError. def redirect_to(options = {}, response_status = {}) #:doc: raise ActionControllerError.new("Cannot redirect to nil!") unless options raise AbstractController::DoubleRenderError if response_body -- cgit v1.2.3 From 80768b739ed7e2053d85a01dd5fa60bde67aad9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 26 Oct 2011 09:31:56 +0200 Subject: Responders now return 204 No Content for API requests without a response body (as in the new scaffold) --- .../lib/action_controller/metal/responder.rb | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index c7827309dd..b932302a60 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -202,10 +202,8 @@ module ActionController #:nodoc: display resource elsif post? display resource, :status => :created, :location => api_location - elsif has_empty_resource_definition? - display empty_resource, :status => :ok else - head :ok + head :no_content end end @@ -269,24 +267,6 @@ module ActionController #:nodoc: @action ||= ACTIONS_FOR_VERBS[request.request_method_symbol] end - # Check whether resource needs a specific definition of empty resource to be valid - # - def has_empty_resource_definition? - respond_to?("empty_#{format}_resource") - end - - # Delegate to proper empty resource method - # - def empty_resource - send("empty_#{format}_resource") - end - - # Return a valid empty JSON resource - # - def empty_json_resource - "{}" - end - def resource_errors respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors end -- cgit v1.2.3 From 6ac56ac93bd9e8a3e003f29eff2816218f0e5db6 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 7 Nov 2011 17:58:03 +0530 Subject: fix incorrect code example --- actionpack/lib/action_controller/metal/mime_responds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index 00bd1706e7..ca383be76b 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -182,7 +182,7 @@ module ActionController #:nodoc: # # def index # @people = Person.all - # respond_with(@person) + # respond_with(@people) # end # end # -- cgit v1.2.3 From a766d834a73efe6a59cbfaf4f25ab73c088465d7 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 11 Nov 2011 19:37:54 +0200 Subject: Fix wording and minor typos in the Responder RDoc --- actionpack/lib/action_controller/metal/responder.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/responder.rb b/actionpack/lib/action_controller/metal/responder.rb index c7827309dd..2f19c76bff 100644 --- a/actionpack/lib/action_controller/metal/responder.rb +++ b/actionpack/lib/action_controller/metal/responder.rb @@ -84,8 +84,8 @@ module ActionController #:nodoc: # # === Custom options # - # respond_with also allow you to pass options that are forwarded - # to the underlying render call. Those options are only applied success + # respond_with also allows you to pass options that are forwarded + # to the underlying render call. Those options are only applied for success # scenarios. For instance, you can do the following in the create method above: # # def create @@ -95,7 +95,7 @@ module ActionController #:nodoc: # respond_with(@project, @task, :status => 201) # end # - # This will return status 201 if the task was saved with success. If not, + # This will return status 201 if the task was saved successfully. If not, # it will simply ignore the given options and return status 422 and the # resource errors. To customize the failure scenario, you can pass a # a block to respond_with: @@ -224,7 +224,7 @@ module ActionController #:nodoc: alias :navigation_location :resource_location alias :api_location :resource_location - # If a given response block was given, use it, otherwise call render on + # If a response block was given, use it, otherwise call render on # controller. # def default_render -- cgit v1.2.3 From 5bcd119b8d9bb6d88c949956de1ce13c2673b877 Mon Sep 17 00:00:00 2001 From: lest Date: Tue, 22 Nov 2011 13:34:13 +0300 Subject: move show_detailed_exceptions? to Rescue module --- actionpack/lib/action_controller/metal/rescue.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/rescue.rb b/actionpack/lib/action_controller/metal/rescue.rb index eb037aa1b0..736ff5b31c 100644 --- a/actionpack/lib/action_controller/metal/rescue.rb +++ b/actionpack/lib/action_controller/metal/rescue.rb @@ -3,6 +3,11 @@ module ActionController #:nodoc: extend ActiveSupport::Concern include ActiveSupport::Rescuable + included do + config_accessor :consider_all_requests_local + self.consider_all_requests_local = false if consider_all_requests_local.nil? + end + def rescue_with_handler(exception) if (exception.respond_to?(:original_exception) && (orig_exception = exception.original_exception) && @@ -12,10 +17,15 @@ module ActionController #:nodoc: super(exception) end + def show_detailed_exceptions? + consider_all_requests_local || request.local? + end + private def process_action(*args) super rescue Exception => exception + request.env['action_dispatch.show_detailed_exceptions'] = show_detailed_exceptions? rescue_with_handler(exception) || raise(exception) end end -- cgit v1.2.3 From 7fcc8c0a1f38c77b12cb6ffe81fb2887e6c60b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 23 Nov 2011 23:45:27 +0000 Subject: Rely solely on active_model_serializer and remove the fancy constant lookup. --- actionpack/lib/action_controller/metal/serialization.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb index 9bb665a9ae..9fb49f512e 100644 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -13,7 +13,9 @@ module ActionController end def _render_option_json(json, options) - json = json.active_model_serializer.new(json, serialization_scope) if json.respond_to?(:active_model_serializer) + if json.respond_to?(:active_model_serializer) && (serializer = json.active_model_serializer) + json = serializer.new(json, serialization_scope) + end super end -- cgit v1.2.3 From 696d01f7f4a8ed787924a41cce6df836cd73c46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 09:49:54 +0000 Subject: Add docs to serializers. Update CHANGELOGs. --- .../lib/action_controller/metal/serialization.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb index 9fb49f512e..628d5996d7 100644 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ b/actionpack/lib/action_controller/metal/serialization.rb @@ -1,4 +1,27 @@ module ActionController + # Action Controller Serialization + # + # Overrides render :json to check if the given object implements +active_model_serializer+ + # as a method. If so, use the returned serializer instead of calling +to_json+ in the object. + # + # This module also provides a serialization_scope method that allows you to configure the + # +serialization_scope+ of the serializer. Most apps will likely set the +serialization_scope+ + # to the current user: + # + # class ApplicationController < ActionController::Base + # serialization_scope :current_user + # end + # + # If you need more complex scope rules, you can simply override the serialization_scope: + # + # class ApplicationController < ActionController::Base + # private + # + # def serialization_scope + # current_user + # end + # end + # module Serialization extend ActiveSupport::Concern -- cgit v1.2.3 From 0a4035b12a6c59253cb60f9e3456513c6a6a9d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 25 Nov 2011 19:29:39 +0000 Subject: Revert the serializers API as other alternatives are now also under discussion --- .../lib/action_controller/metal/serialization.rb | 51 ---------------------- 1 file changed, 51 deletions(-) delete mode 100644 actionpack/lib/action_controller/metal/serialization.rb (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/serialization.rb b/actionpack/lib/action_controller/metal/serialization.rb deleted file mode 100644 index 628d5996d7..0000000000 --- a/actionpack/lib/action_controller/metal/serialization.rb +++ /dev/null @@ -1,51 +0,0 @@ -module ActionController - # Action Controller Serialization - # - # Overrides render :json to check if the given object implements +active_model_serializer+ - # as a method. If so, use the returned serializer instead of calling +to_json+ in the object. - # - # This module also provides a serialization_scope method that allows you to configure the - # +serialization_scope+ of the serializer. Most apps will likely set the +serialization_scope+ - # to the current user: - # - # class ApplicationController < ActionController::Base - # serialization_scope :current_user - # end - # - # If you need more complex scope rules, you can simply override the serialization_scope: - # - # class ApplicationController < ActionController::Base - # private - # - # def serialization_scope - # current_user - # end - # end - # - module Serialization - extend ActiveSupport::Concern - - include ActionController::Renderers - - included do - class_attribute :_serialization_scope - end - - def serialization_scope - send(_serialization_scope) - end - - def _render_option_json(json, options) - if json.respond_to?(:active_model_serializer) && (serializer = json.active_model_serializer) - json = serializer.new(json, serialization_scope) - end - super - end - - module ClassMethods - def serialization_scope(scope) - self._serialization_scope = scope - end - end - end -end -- cgit v1.2.3 From 38ab982cfff98570b5f12933cff489364845789c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Nov 2011 09:52:52 +0100 Subject: Log 'Filter chain halted as CALLBACKNAME rendered or redirected' every time a before callback halts. --- actionpack/lib/action_controller/metal/instrumentation.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/metal') diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index 777a0ab343..640ebf5f00 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -64,7 +64,12 @@ module ActionController end end - protected + private + + # A hook invoked everytime a before callback is halted. + def halted_callback_hook(filter) + ActiveSupport::Notifications.instrument("halted_callback.action_controller", :filter => filter) + end # A hook which allows you to clean up any time taken into account in # views wrongly, like database querying time. -- cgit v1.2.3