Rails 5.0.0.rc1 (May 06, 2016)
Add
ActionController#helpersto get access to the view context at the controller
level.Rafael Mendonça França
Rails 5.0.0.beta4 (April 27, 2016)
Routing: Refactor
:actiondefault handling to ensure that path
parameters are not mutated during route generation.Andrew White
Add extension synonyms
ymlandyamlfor MIME typeapplication/x-yaml.bogdanvlviv
Adds support for including ActionController::Cookies in API controllers.
Previously, including the module would raise when trying to define
acookieshelper method. Skip calling #helper_method if it is not
defined – if we don’t have helpers, we needn’t define one.Fixes #24304
Ryan T. Hosford
ETags: Introduce
Response#strong_etag=and#weak_etag=and analogous
options forfresh_whenandstale?.Response#etag=sets a weak ETag.Strong ETags are desirable when you’re serving byte-for-byte identical
responses that support Range requests, like PDFs or videos (typically
done by reproxying the response from a backend storage service).
Also desirable when fronted by some CDNs that support strong ETags
only, like Akamai.Jeremy Daer
ETags: No longer strips quotes (“) from ETag values before comparing them.
Quotes are significant, part of the ETag. A quoted ETag and an unquoted
one are not the same entity.Jeremy Daer
ETags: Support
If-None-Match: *. Rarely useful for GET requests; meant
to provide some optimistic concurrency control for PUT requests.Jeremy Daer
ActionDispatch::ParamsParseris deprecated and was removed from the middleware
stack. To configure the parameter parsers useActionDispatch::Request.parameter_parsers=.tenderlove
When a
respond_tocollector with a block doesn’t have a response, then
a:no_contentresponse should be rendered. This brings the default
rendering behavior introduced by https://github.com/rails/rails/issues/19036
to controller methods employingrespond_to.Justin Coyne
Add
ActionController::Parameters#digon Ruby 2.3 and greater, which
behaves the same asHash#dig.Sean Griffin
Add request headers in the payload of the
start_processing.action_controller
andprocess_action.action_controllernotifications.Gareth du Plooy
Add
action_dispatch_integration_testload hook. The hook can be used to
extendActionDispatch::IntegrationTestonce it has been loaded.Yuichiro Kaneko
Update default rendering policies when the controller action did
not explicitly indicate a response.For API controllers, the implicit render always renders "204 No Content”
and does not account for any templates.For other controllers, the following conditions are checked:
First, if a template exists for the controller action, it is rendered.
This template lookup takes into account the action name, locales, format,
variant, template handlers, etc. (seerenderfor details).Second, if other templates exist for the controller action but is not in
the right format (or variant, etc.), anActionController::UnknownFormat
is raised. The list of available templates is assumed to be a complete
enumeration of all the possible formats (or variants, etc.); that is,
having only HTML and JSON templates indicate that the controller action is
not meant to handle XML requests.Third, if the current request is an “interactive” browser request (the user
navigated here by entering the URL in the address bar, submitting a form,
clicking on a link, etc. as opposed to an XHR or non-browser API request),
ActionView::UnknownFormatis raised to display a helpful error
message.Finally, it falls back to the same “204 No Content” behavior as API controllers.
Godfrey Chan, Jon Moss, Kasper Timm Hansen, Mike Clark, Matthew Draper
Rails 5.0.0.beta3 (February 24, 2016)
Add “application/gzip” as a default mime type.
Mehmet Emin İNAÇ
Add request encoding and response parsing to integration tests.
What previously was:
require 'test_helper' class ApiTest < ActionDispatch::IntegrationTest test 'creates articles' do assert_difference -> { Article.count } do post articles_path(format: :json), params: { article: { title: 'Ahoy!' } }.to_json, headers: { 'Content-Type' => 'application/json' } end assert_equal({ 'id' => Article.last.id, 'title' => 'Ahoy!' }, JSON.parse(response.body)) end end
Can now be written as:
require 'test_helper' class ApiTest < ActionDispatch::IntegrationTest test 'creates articles' do assert_difference -> { Article.count } do post articles_path, params: { article: { title: 'Ahoy!' } }, as: :json end assert_equal({ 'id' => Article.last.id, 'title' => 'Ahoy!' }, response.parsed_body) end end
Passing
as: :jsonto integration test request helpers will set the format,
content type and encode the parameters as JSON.Then on the response side,
parsed_bodywill parse the body according to the
content type the response has.Currently JSON is the only supported MIME type. Add your own with
ActionDispatch::IntegrationTest.register_encoder.Kasper Timm Hansen
Add “image/svg+xml” as a default mime type.
DHH
Rails 5.0.0.beta2 (February 01, 2016)
Add
-gand-coptions tobin/rails routes. These options return the urlname,verband
pathfield that match the pattern or match a specific controller.Deprecate
CONTROLLERenv variable inbin/rails routes.See #18902.
Anton Davydov, Vipul A M
Response etags to always be weak: Prefixes ‘W/’ to value returned by
ActionDispatch::Http::Cache::Response#etag=, such that etags set in
fresh_whenandstale?are weak.Fixes #17556.
Abhishek Yadav
Provide the name of HTTP Status code in assertions.
Sean Collins
More explicit error message when running
rake routes.CONTROLLERargument
can now be supplied in different ways:
Rails::WelcomeController,Rails::Welcome,rails/welcome.Fixes #22918.
Edouard Chin
Allow
ActionController::Parametersinstances as an argument to URL
helper methods. AnArgumentErrorwill be raised if the passed parameters
are not secure.Fixes #22832.
Prathamesh Sonpatki
Add option for per-form CSRF tokens.
Greg Ose, Ben Toews
Fix
ActionController::Parameters#convert_parameters_to_hashesto return filtered
or unfiltered values based on from where it is called,to_horto_unsafe_h
respectively.Fixes #22841.
Prathamesh Sonpatki
Add
ActionController::Parameters#include?Justin Coyne
Rails 5.0.0.beta1 (December 18, 2015)
Deprecate
redirect_to :backin favor ofredirect_back, which accepts a
requiredfallback_locationargument, thus eliminating the possibility of a
RedirectBackError.Derek Prior
Add
redirect_backmethod toActionController::Redirectingto provide a
way to safely redirect to theHTTP_REFERERif it is present, falling back
to a provided redirect otherwise.Derek Prior
ActionController::TestCasewill be moved to its own gem in Rails 5.1.With the speed improvements made to
ActionDispatch::IntegrationTestwe no
longer need to keep two separate code bases for testing controllers. In
Rails 5.1ActionController::TestCasewill be deprecated and moved into a
gem outside of Rails source.This is a documentation deprecation so that going forward new tests will use
ActionDispatch::IntegrationTestinstead ofActionController::TestCase.Eileen M. Uchitelle
Add a
response_formatoption toActionDispatch::DebugExceptions
to configure the format of the response when errors occur in
development mode.If
response_formatis:defaultthe debug info will be rendered
in an HTML page. In the other hand, if the provided value is:api
the debug info will be rendered in the original response format.Jorge Bejar
Change the
protect_from_forgeryprepend default tofalse.Per this comment
https://github.com/rails/rails/pull/18334#issuecomment-69234050 we want
protect_from_forgeryto default toprepend: false.protect_from_forgerywill now be inserted into the callback chain at the
point it is called in your application. This is useful for cases where you
want toprotect_from_forgeryafter you perform required authentication
callbacks or other callbacks that are required to run after forgery protection.If you want
protect_from_forgerycallbacks to always run first, regardless of
position they are called in your application then you can addprepend: true
to yourprotect_from_forgerycall.Example:
protect_from_forgery prepend: true
Eileen M. Uchitelle
In url_for, never append a question mark to the URL when the query string
is empty anyway. (It used to do that when called likeurl_for(controller:.)
'x', action: 'y', q: {})Paul Grayson
Catch invalid UTF-8 querystring values and respond with BadRequest
Check querystring params for invalid UTF-8 characters, and raise an
ActionController::BadRequest error if present. Previously these strings
would typically trigger errors further down the stack.Grey Baker
Parse RSS/ATOM responses as XML, not HTML.
Alexander Kaupanin
Show helpful message in
BadRequestexceptions due to invalid path
parameter encodings.Fixes #21923.
Agis Anastasopoulos
Add the ability of returning arbitrary headers to
ActionDispatch::Static.Now ActionDispatch::Static can accept HTTP headers so that developers
will have control of returning arbitrary headers like
‘Access-Control-Allow-Origin’ when a response is delivered. They can be
configured with#config:Example:
config.public_file_server.headers = {
“Cache-Control” => “public, max-age=60”,
“Access-Control-Allow-Origin” => “http://rubyonrails.org”
}Yuki Nishijima
Allow multiple
rootroutes in same scope level. Example:Example:
root ‘blog#show’, constraints: ->(req) { Hostname.blog_site?(req.host) }
root ‘landing#show’Rafael Sales
Fix regression in mounted engine named routes generation for app deployed to
a subdirectory.relative_url_rootwas prepended to the path twice (e.g.
“/subdir/subdir/engine_path” instead of “/subdir/engine_path”)Fixes #20920. Fixes #21459.
Matthew Erhard
ActionDispatch::Response#newno longer applies default headers. If you want
default headers applied to the response object, then call
ActionDispatch::Response.create. This change only impacts people who are
directly constructing anActionDispatch::Responseobject.Accessing mime types via constants like
Mime::HTMLis deprecated. Please
change code like this:Mime::HTML
To this:
Mime[:html]
This change is so that Rails will not manage a list of constants, and fixes
an issue where if a type isn’t registered you could possibly get the wrong
object.Mime[:html]is available in older versions of Rails, too, so you can
safely change libraries and plugins and maintain compatibility with
multiple versions of Rails.url_fordoes not modify its arguments when generating polymorphic URLs.Bernerd Schaefer
Make it easier to opt in to
config.force_sslandconfig.ssl_optionsby
making them less dangerous to try and easier to disable.SSL redirect:
- Move
:hostand:portoptions withinredirect: { … }. Deprecate. - Introduce
:statusand:bodyto customize the redirect response. The 301 permanent default makes it difficult to test the redirect and back out of it since browsers remember the 301. Test with a 302 or 307 instead, then switch to 301 once you’re confident that all is well.
HTTP Strict Transport Security (HSTS):
- Shorter max-age. Shorten the default max-age from 1 year to 180 days, the low end for https://www.ssllabs.com/ssltest/ grading and greater than the 18-week minimum to qualify for browser preload lists.
- Disabling HSTS. Setting
hsts: falsenow setshsts { expires: 0 }instead of omitting the header. Omitting does nothing to disable HSTS since browsers hang on to your previous settings until they expire. Sending{ hsts: { expires: 0 }}flushes out old browser settings and actually disables HSTS: http://tools.ietf.org/html/rfc6797#section-6.1.1 - HSTS Preload. Introduce
preload: trueto set thepreloadflag, indicating that your site may be included in browser preload lists, including Chrome, Firefox, Safari, IE11, and Edge. Submit your site: https://hstspreload.appspot.com
Jeremy Daer
- Move
Update
ActionController::TestSession#fetchto behave more like
ActionDispatch::Request::Session#fetchwhen using non-string keys.Jeremy Friesen
Using strings or symbols for middleware class names is deprecated. Convert
things like this:middleware.use “Foo::Bar”
to this:
middleware.use Foo::Bar
ActionController::TestSessionnow accepts a default value as well as
a block for generating a default value based off the key provided.This fixes calls to
session#fetchinApplicationControllerinstances that
take more two arguments or a block from raisingArgumentError: wrongwhen performing controller tests.
number of arguments (2 for 1)Matthew Gerrior
Fix
ActionController::Parameters#fetchoverwritingKeyErrorreturned by
default block.Jonas Schuber Erlandsson, Roque Pinel
ActionController::Parametersno longer inherits from
HashWithIndifferentAccessInheriting from
HashWithIndifferentAccessallowed users to call any
enumerable methods onParametersobject, resulting in a risk of losing the
permitted?status or even getting back a pureHashobject instead of
aParametersobject with proper sanitization.By not inheriting from
HashWithIndifferentAccess, we are able to make
sure that all methods that are defined inParametersobject will return
a properParametersobject with a correctpermitted?flag.Prem Sichanugrist
Replaced
ActiveSupport::Concurrency::LatchwithConcurrent::CountDownLatch
from the concurrent-ruby gem.Jerry D'Antonio
Add ability to filter parameters based on parent keys.
# matches {credit_card: {code: “xxxx”}}
# doesn’t match {file: { code: “xxxx”}}
config.filter_parameters += [ “credit_card.code” ]See #13897.
Guillaume Malette
Deprecate passing first parameter as
Hashand default status code forheadmethod.Mehmet Emin İNAÇ
Adds
Rack::Utils::ParameterTypeErrorandRack::Utils::InvalidParameterError
to the rescue_responses hash inExceptionWrapper(Rack recommends
integrators serve 400s for both of these).Grey Baker
Add support for API only apps.
ActionController::APIis added as a replacement of
ActionController::Basefor this kind of applications.Santiago Pastorino, Jorge Bejar
Remove
assignsandassert_template. Both methods have been extracted
into a gem at https://github.com/rails/rails-controller-testing.See #18950.
Alan Guo Xiang Tan
FileHandlerandStaticmiddleware initializers acceptindexargument
to configure the directory index file name. Defaults toindex(as in
index.html).See #20017.
Eliot Sykes
Deprecate
:nothingoption forrendermethod.Mehmet Emin İNAÇ
Fix
rake routesnot showing the right format when
nesting multiple routes.See #18373.
Ravil Bayramgalin
Add ability to override default form builder for a controller.
class AdminController < ApplicationController
default_form_builder AdminFormBuilder
endKevin McPhillips
For actions with no corresponding templates, render
head :no_content
instead of raising an error. This allows for slimmer API controller
methods that simply work, without needing further instructions.See #19036.
Stephen Bussey
Provide friendlier access to request variants.
request.variant = :phone
request.variant.phone? # true
request.variant.tablet? # falserequest.variant = [:phone, :tablet]
request.variant.phone? # true
request.variant.desktop? # false
request.variant.any?(:phone, :desktop) # true
request.variant.any?(:desktop, :watch) # falseGeorge Claghorn
Fix regression where a gzip file response would have a Content-type,
even when it was a 304 status code.See #19271.
Kohei Suzuki
Fix handling of empty
X_FORWARDED_HOSTheader inraw_host_with_port.Previously, an empty
X_FORWARDED_HOSTheader would cause
Actiondispatch::Http:URL.raw_host_with_portto returnnil, causing
Actiondispatch::Http:URL.hostto raise aNoMethodError.Adam Forsyth
Allow
Beareras token-keyword inAuthorization-Header.Additionally to
Token, the keywordBeareris acceptable as a keyword
for the auth-token. TheBearerkeyword is described in the original
OAuth RFC and used in libraries like Angular-JWT.See #19094.
Peter Schröder
Drop request class from
RouteSetconstructor.If you would like to use a custom request class, please subclass and implement
therequest_classmethod.Fallback to
ENV['RAILS_RELATIVE_URL_ROOT']inurl_for.Fixed an issue where the
RAILS_RELATIVE_URL_ROOTenvironment variable is not
prepended to the path whenurl_foris called. IfSCRIPT_NAME(used by Rack)
is set, it takes precedence.Fixes #5122.
Yasyf Mohamedali
Partitioning of routes is now done when the routes are being drawn. This
helps to decrease the time spent filtering the routes during the first request.Guo Xiang Tan
Fix regression in functional tests. Responses should have default headers
assigned.See #18423.
Jeremy Kemper, Yves Senn
Deprecate
AbstractController#skip_action_callbackin favor of individual skip_callback methods
(which can be made to raise an error if no callback was removed).Iain Beeston
Alias the
ActionDispatch::Request#uuidmethod toActionDispatch::Request#request_id.
Due to implementation,config.log_tags = [:request_id]also works in substitute
forconfig.log_tags = [:uuid].David Ilizarov
Change filter on /rails/info/routes to use an actual path regexp from rails
and not approximate javascript version. Oniguruma supports much more
extensive list of features than javascript regexp engine.Fixes #18402.
Ravil Bayramgalin
Non-string authenticity tokens do not raise NoMethodError when decoding
the masked token.Ville Lautanala
Add
http_cache_foreverto Action Controller, so we can cache a response
that never gets expired.arthurnn
ActionController#translatesupports symbols as shortcuts.
When a shortcut is given it also performs the lookup without the action
name.Max Melentiev
Expand
ActionController::ConditionalGet#fresh_whenandstale?to also
accept a collection of records as the first argument, so that the
following code can be written in a shorter form.# Before
def index
@articles = Article.all
fresh_when(etag: @articles, last_modified: @articles.maximum(:updated_at))
end# After
def index
@articles = Article.all
fresh_when(@articles)
endclaudiob
Explicitly ignored wildcard verbs when searching for HEAD routes before fallback
Fixes an issue where a mounted rack app at root would intercept the HEAD
request causing an incorrect behavior during the fall back to GET requests.Example:
draw do
get ‘/home’ => ‘test#index’
mount rack_app, at: ‘/’
end
head ‘/home’
assert_response :successIn this case, a HEAD request runs through the routes the first time and fails
to match anything. Then, it runs through the list with the fallback and matches
get '/home'. The original behavior would match the rack app in the first pass.Terence Sun
Migrating xhr methods to keyword arguments syntax
inActionController::TestCaseandActionDispatch::IntegrationOld syntax:
xhr :get, :create, params: { id: 1 }
New syntax example:
get :create, params: { id: 1 }, xhr: true
Kir Shatrov
Migrating to keyword arguments syntax in
ActionController::TestCaseand
ActionDispatch::IntegrationHTTP request methods.Example:
post :create, params: { y: x }, session: { a: ‘b’ }
get :view, params: { id: 1 }
get :view, params: { id: 1 }, format: :jsonKir Shatrov
Preserve default url options when generating URLs.
Fixes an issue that would cause
default_url_optionsto be lost when
generating URLs with fewer positional arguments than parameters in the
route definition.Tekin Suleyman
Deprecate
*_via_redirectintegration test methods.Use
follow_redirect!manually after the request call for the same behavior.Aditya Kapoor
Add
ActionController::Rendererto render arbitrary templates
outside controller actions.Its functionality is accessible through class methods
renderand
rendererofActionController::Base.Ravil Bayramgalin
Support
:assignsoption when rendering with controllers/mailers.Ravil Bayramgalin
Default headers, removed in controller actions, are no longer reapplied on
the test response.Jonas Baumann
Deprecate all
*_filtercallbacks in favor of*_actioncallbacks.Rafael Mendonça França
Allow you to pass
prepend: falsetoprotect_from_forgeryto have the
verification callback appended instead of prepended to the chain.
This allows you to let the verification step depend on prior callbacks.Example:
class ApplicationController < ActionController::Base
before_action :authenticate
protect_from_forgery prepend: false, unless: -> { @authenticated_by.oauth? }private
def authenticate
if oauth_request?
# authenticate with oauth
@authenticated_by = ‘oauth’.inquiry
else
# authenticate with cookies
@authenticated_by = ‘cookie’.inquiry
end
end
endJosef Šimánek
Remove
ActionController::HideActions.Ravil Bayramgalin
Remove
respond_to/respond_withplaceholder methods, this functionality
has been extracted to therespondersgem.Carlos Antonio da Silva
Remove deprecated assertion files.
Rafael Mendonça França
Remove deprecated usage of string keys in URL helpers.
Rafael Mendonça França
Remove deprecated
only_pathoption on*_pathhelpers.Rafael Mendonça França
Remove deprecated
NamedRouteCollection#helpers.Rafael Mendonça França
Remove deprecated support to define routes with
:tooption that doesn’t contain#.Rafael Mendonça França
Remove deprecated
ActionDispatch::Response#to_ary.Rafael Mendonça França
Remove deprecated
ActionDispatch::Request#deep_munge.Rafael Mendonça França
Remove deprecated
ActionDispatch::Http::Parameters#symbolized_path_parameters.Rafael Mendonça França
Remove deprecated option
use_routein controller tests.Rafael Mendonça França
Ensure
append_info_to_payloadis called even if an exception is raised.Fixes an issue where when an exception is raised in the request the additional
payload data is not available.See #14903.
Dieter Komendera, Margus Pärt
Correctly rely on the response’s status code to handle calls to
head.Robin Dupret
Using
headmethod returns empty response_body instead
of returning a single space “ ”.The old behavior was added as a workaround for a bug in an early
version of Safari, where the HTTP headers are not returned correctly
if the response body has a 0-length. This is been fixed since and
the workaround is no longer necessary.Fixes #18253.
Prathamesh Sonpatki
Fix how polymorphic routes works with objects that implement
to_model.Travis Grathwell
Stop converting empty arrays in
paramstonil.This behavior was introduced in response to CVE-2012-2660, CVE-2012-2694
and CVE-2013-0155ActiveRecord now issues a safe query when passing an empty array into
a where clause, so there is no longer a need to defend against this type
of input (any nils are still stripped from the array).Chris Sinjakli
Fixed usage of optional scopes in url helpers.
Alex Robbin
Fixed handling of positional url helper arguments when
format: false.Fixes #17819.
Andrew White, Tatiana Soukiassian
Please check 4-2-stable for previous changes.