diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index a9233014e476a077c0973498fe81c1f5682254b2..a06484ea20ad945660b1e25f36ca2dec9c78ff09 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Deprecate `:nothing` option for `render` method. + + *Mehmet Emin İNAÇ* + * Fix `rake routes` not showing the right format when nesting multiple routes. diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index 2d15c39d887f546c73d8d9874f11541e07a8375e..b9ae8dd5ea33b18136da806800dd911fbe7fa35f 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -79,6 +79,7 @@ def _normalize_options(options) #:nodoc: end if options.delete(:nothing) + ActiveSupport::Deprecation.warn("`:nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.") options[:body] = nil end diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index c1be2c9afe23faa3f0cfecc129d44b512ff603c2..1690bdd54208e042868485dbca9f43bf50600056 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -380,7 +380,7 @@ def dispatcher defaults end class ResourcesController < ActionController::Base - def index() render :nothing => true end + def index() head :ok end alias_method :show, :index end diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 21586e2193ac1d094607ded1aaee1d19b53e7450..cbf333c77271b56ed82201a9c1622ba2fc4047fb 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -123,7 +123,7 @@ def show module Admin class InnerModuleController < ActionController::Base def index - render :nothing => true + head :ok end def redirect_to_index diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index f7ad8e51586224f3d68f31887a1b52ba12414ee7..3240185414e3c067b435197a8546b280ebcdc7e2 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -13,7 +13,7 @@ class EmptyController < ActionController::Base class NonEmptyController < ActionController::Base def public_action - render :nothing => true + head :ok end end @@ -29,7 +29,7 @@ def default_url_options class OptionalDefaultUrlOptionsController < ActionController::Base def show - render nothing: true + head :ok end def default_url_options diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb index 0ff0a1ef616a047e2d58fe681debe4cd7f80dcb5..60a000c160a2568d28301366e6b3351bc2c1c83c 100644 --- a/actionpack/test/controller/flash_test.rb +++ b/actionpack/test/controller/flash_test.rb @@ -57,7 +57,7 @@ def use_flash_after_reset_session def std_action @flash_copy = {}.update(flash) - render :nothing => true + head :ok end def filter_halting_action diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index 03a4ad7823e117bf52599ee79948faa06d70d9d3..4ae1b20d433d337c53e60fcdb95648d77a8086d5 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -19,7 +19,7 @@ def never_executed end def show - render :nothing => true + head :ok end def redirector @@ -170,7 +170,7 @@ def test_process_action_with_wrapped_parameters def test_process_action_with_view_runtime get :show wait - assert_match(/\(Views: [\d.]+ms\)/, logs[1]) + assert_match /Completed 200 OK in [\d]ms/, logs[1] end def test_append_info_to_payload_is_called_even_with_exception diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 79e2104789961a421188fabc9a0cefb2963b0374..cabacad940f21146e25b696905792e5904676d72 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -120,6 +120,10 @@ def conditional_hello_with_cache_control_headers render :action => 'hello_world' end + def respond_with_empty_body + render nothing: true + end + def conditional_hello_with_bangs render :action => 'hello_world' end @@ -270,6 +274,12 @@ def test_expires_now_with_cache_control_headers assert_match(/no-transform/, @response.headers["Cache-Control"]) end + def test_render_nothing_deprecated + assert_deprecated do + get :respond_with_empty_body + end + end + def test_date_header_when_expires_in time = Time.mktime(2011,10,30) Time.stubs(:now).returns(time) diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index f8cf79a2574adbe645914baa6b70fabd98026ba9..82c808754c5968cb0e1b45b0b816f62f6cb15987 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -72,17 +72,17 @@ class RequestForgeryProtectionControllerUsingNullSession < ActionController::Bas def signed cookies.signed[:foo] = 'bar' - render :nothing => true + head :ok end def encrypted cookies.encrypted[:foo] = 'bar' - render :nothing => true + head :ok end def try_to_reset_session reset_session - render :nothing => true + head :ok end end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 37f27c5d3654e286ba8fa99bff6f85660bc35100..fbfc891d1973018395b64a3676d434b8c04909f3 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -137,13 +137,13 @@ def create def delete_cookie cookies.delete("foo") - render nothing: true + head :ok end def test_assigns @foo = "foo" @foo_hash = { foo: :bar } - render nothing: true + head :ok end def test_without_body @@ -177,7 +177,7 @@ def setup class ViewAssignsController < ActionController::Base def test_assigns @foo = "foo" - render nothing: true + head :ok end def view_assigns diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb index 7cbc77f11f019c6e5d8ac8dd175a76598cddcf69..d69c070edea44dedb5871c3d0fe89a3d009ee3a8 100644 --- a/actionview/test/actionpack/controller/render_test.rb +++ b/actionview/test/actionpack/controller/render_test.rb @@ -358,7 +358,7 @@ def layout_overriding_layout end def rendering_nothing_on_layout - render :nothing => true + head :ok end def render_to_string_with_assigns diff --git a/guides/source/layouts_and_rendering.md b/guides/source/layouts_and_rendering.md index 737f3929954639bfded90c878d877cf8bb72ffde..94cd7297e2b0c8eedd542f9fcc85a80ac4bee1bd 100644 --- a/guides/source/layouts_and_rendering.md +++ b/guides/source/layouts_and_rendering.md @@ -103,32 +103,6 @@ In most cases, the `ActionController::Base#render` method does the heavy lifting TIP: If you want to see the exact results of a call to `render` without needing to inspect it in a browser, you can call `render_to_string`. This method takes exactly the same options as `render`, but it returns a string instead of sending a response back to the browser. -#### Rendering Nothing - -Perhaps the simplest thing you can do with `render` is to render nothing at all: - -```ruby -render nothing: true -``` - -If you look at the response for this using cURL, you will see the following: - -```bash -$ curl -i 127.0.0.1:3000/books -HTTP/1.1 200 OK -Connection: close -Date: Sun, 24 Jan 2010 09:25:18 GMT -Transfer-Encoding: chunked -Content-Type: */*; charset=utf-8 -X-Runtime: 0.014297 -Set-Cookie: _blog_session=...snip...; path=/; HttpOnly -Cache-Control: no-cache -``` - -We see there is an empty response (no data after the `Cache-Control` line), but the request was successful because Rails has set the response to 200 OK. You can set the `:status` option on render to change this response. Rendering nothing can be useful for Ajax requests where all you want to send back to the browser is an acknowledgment that the request was completed. - -TIP: You should probably be using the `head` method, discussed later in this guide, instead of `render :nothing`. This provides additional flexibility and makes it explicit that you're only generating HTTP headers. - #### Rendering an Action's View If you want to render the view that corresponds to a different template within the same controller, you can use `render` with the name of the view: diff --git a/railties/test/application/middleware/session_test.rb b/railties/test/application/middleware/session_test.rb index a8dc79d10af29b4b09a02ad55b021961d500e5dc..25eadfc387cf2f1155aeda7d40fa0a284743db6a 100644 --- a/railties/test/application/middleware/session_test.rb +++ b/railties/test/application/middleware/session_test.rb @@ -35,7 +35,7 @@ def index flash[:notice] = "notice" end - render nothing: true + head :ok end end @@ -60,7 +60,7 @@ class FooController < ActionController::Base def write_session session[:foo] = 1 - render nothing: true + head :ok end def read_session @@ -101,7 +101,7 @@ class FooController < ActionController::Base def write_cookie cookies[:foo] = '1' - render nothing: true + head :ok end def read_cookie @@ -139,7 +139,7 @@ def read_cookie class FooController < ActionController::Base def write_session session[:foo] = 1 - render nothing: true + head :ok end def read_session @@ -184,7 +184,7 @@ def read_raw_cookie class FooController < ActionController::Base def write_session session[:foo] = 1 - render nothing: true + head :ok end def read_session @@ -234,12 +234,12 @@ class FooController < ActionController::Base def write_raw_session # {"session_id"=>"1965d95720fffc123941bdfb7d2e6870", "foo"=>1} cookies[:_myapp_session] = "BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTE5NjVkOTU3MjBmZmZjMTIzOTQxYmRmYjdkMmU2ODcwBjsAVEkiCGZvbwY7AEZpBg==--315fb9931921a87ae7421aec96382f0294119749" - render nothing: true + head :ok end def write_session session[:foo] = session[:foo] + 1 - render nothing: true + head :ok end def read_session @@ -293,12 +293,12 @@ class FooController < ActionController::Base def write_raw_session # {"session_id"=>"1965d95720fffc123941bdfb7d2e6870", "foo"=>1} cookies[:_myapp_session] = "BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTE5NjVkOTU3MjBmZmZjMTIzOTQxYmRmYjdkMmU2ODcwBjsAVEkiCGZvbwY7AEZpBg==--315fb9931921a87ae7421aec96382f0294119749" - render nothing: true + head :ok end def write_session session[:foo] = session[:foo] + 1 - render nothing: true + head :ok end def read_session