28 KiB
Rails 4.0.0 (unreleased)
-
Rename all action callbacks from *_filter to *_action to avoid the misconception that these callbacks are only suited for transforming or halting the response. With the new style, it's more inviting to use them as they were intended, like setting shared ivars for views.
Example:
class PeopleController < ActionController::Base before_action :set_person, except: [ :index, :new, :create ] before_action :ensure_permission, only: [ :edit, :update ] ... private def set_person @person = current_account.people.find(params[:id]) end def ensure_permission current_person.can_change?(@person) end end
The old *_filter methods still work with no deprecation notice.
DHH
-
Add :if / :unless conditions to fragment cache:
<%= cache @model, if: some_condition(@model) do %>
Stephen Ausman + Fabrizio Regini
-
Add filter capability to ActionController logs for redirect locations:
config.filter_redirect << 'http://please.hide.it/'
Fabrizio Regini
-
Fixed a bug that ignores constraints on a glob route. This was caused because the constraint regular expression is overwritten when the
routes.rb
file is processed. Fixes #7924Maura Fitzgerald
-
More descriptive error messages when calling
render :partial
with an invalid:layout
argument. #8376render :partial => 'partial', :layout => true # results in ActionView::MissingTemplate: Missing partial /true
Yves Senn
-
Sweepers was extracted from Action Controller as
rails-observers
gem.Rafael Mendonça França
-
Add option flag to
CacheHelper#cache
to manually bypass automatic template digests:<% cache project, skip_digest: true do %> ... <% end %>
Drew Ulmer
-
No sort Hash options in #grouped_options_for_select. Sergey Kojin
-
Accept symbols as #send_data :disposition value Elia Schito
-
Add i18n scope to distance_of_time_in_words. Steve Klabnik
-
assert_template
:- is no more passing with empty string.
- is now validating option keys. It accepts:
:layout
,:partial
,:locals
and:count
.
Roberto Soares
-
Allow setting a symbol as path in scope on routes. This is now allowed:
scope :api do resources :users end
It is also possible to pass multiple symbols to scope to shorten multiple nested scopes:
scope :api do scope :v1 do resources :users end end
can be rewritten as:
scope :api, :v1 do resources :users end
Guillermo Iguaran
-
Fix error when using a non-hash query argument named "params" in
url_for
.Before:
url_for(params: "") # => undefined method `reject!' for "":String
After:
url_for(params: "") # => http://www.example.com?params=
tumayun + Carlos Antonio da Silva
-
Render every partial with a new
ActionView::PartialRenderer
. This resolves issues when rendering nested partials. Fix #8197Yves Senn
-
Introduce
ActionView::Template::Handlers::ERB.escape_whitelist
. This is a list of mime types where template text is not html escaped by default. It preventsJack & Joe
from rendering asJack & Joe
for the whitelisted mime types. The default whitelist contains text/plain. Fix #7976Joost Baaij
-
Fix input name when
:multiple => true
and:index
are set.Before:
check_box("post", "comment_ids", { :multiple => true, :index => "foo" }, 1) #=> <input name=\"post[foo][comment_ids]\" type=\"hidden\" value=\"0\" /><input id=\"post_foo_comment_ids_1\" name=\"post[foo][comment_ids]\" type=\"checkbox\" value=\"1\" />
After:
check_box("post", "comment_ids", { :multiple => true, :index => "foo" }, 1) #=> <input name=\"post[foo][comment_ids][]\" type=\"hidden\" value=\"0\" /><input id=\"post_foo_comment_ids_1\" name=\"post[foo][comment_ids][]\" type=\"checkbox\" value=\"1\" />
Fix #8108
Daniel Fox, Grant Hutchins & Trace Wax
-
Clear url helpers when reloading routes.
Santiago Pastorino
-
BestStandardsSupport
middleware now appends it'sX-UA-Compatible
value to app's returned value if any. Fix #8086Nikita Afanasenko
-
date_select
helper acceptswith_css_classes: true
to add css classes similar with type of generated select tags.Pavel Nikitin
-
Only non-js/css under app/assets path will be included in default config.assets.precompile.
Josh Peek
-
Remove support for the RAILS_ASSET_ID environment configuration (no longer needed now that we have the asset pipeline).
Josh Peek
-
Remove old asset_path configuration (no longer needed now that we have the asset pipeline).
Josh Peek
-
assert_template
can be used to assert on the same template with different locals Fix #3675Yves Senn
-
Remove old asset tag concatenation (no longer needed now that we have the asset pipeline).
Josh Peek
-
Accept :remote as symbolic option for
link_to
helper. Riley Lynch -
Warn when the
:locals
option is passed toassert_template
outside of a view test case Fix #3415Yves Senn
-
The
Rack::Cache
middleware is now disabled by default. To enable it, setconfig.action_dispatch.rack_cache = true
and addgem rack-cache
to your Gemfile.Guillermo Iguaran
-
ActionController::Base.page_cache_extension
option is deprecated in favour ofActionController::Base.default_static_extension
.Francesco Rodriguez
-
Action and Page caching has been extracted from Action Dispatch as
actionpack-action_caching
andactionpack-page_caching
gems. Please read theREADME.md
file on both gems for the usage.Francesco Rodriguez
-
Failsafe exception returns text/plain. Steve Klabnik
-
Remove
rack-cache
dependency from Action Pack and declare it on GemfileGuillermo Iguaran
-
Rename internal variables on ActionController::TemplateAssertions to prevent naming collisions. @partials, @templates and @layouts are now prefixed with an underscore. Fix #7459
Yves Senn
-
resource
andresources
don't modify the passed options hash Fix #7777Yves Senn
-
Precompiled assets include aliases from foo.js to foo/index.js and vice versa.
# Precompiles phone-<digest>.css and aliases phone/index.css to phone.css. config.assets.precompile = [ 'phone.css' ] # Precompiles phone/index-<digest>.css and aliases phone.css to phone/index.css. config.assets.precompile = [ 'phone/index.css' ] # Both of these work with either precompile thanks to their aliases. <%= stylesheet_link_tag 'phone', media: 'all' %> <%= stylesheet_link_tag 'phone/index', media: 'all' %>
Jeremy Kemper
-
assert_template
is no more passing with what ever string that matches with the template name.Before when we have a template
/layout/hello.html.erb
,assert_template
was passing with any string that matches. This behavior allowed false positive like:assert_template "layout" assert_template "out/hello"
Now it only passes with:
assert_template "layout/hello" assert_template "hello"
Fixes #3849.
Hugolnx
-
image_tag
will set the same width and height for image if numerical value passed tosize
option.Nihad Abbasov
-
Deprecate Mime::Type#verify_request? and Mime::Type.browser_generated_types, since they are no longer used inside of Rails, they will be removed in Rails 4.1
Michael Grosser
-
ActionDispatch::Http::UploadedFile
now delegatesclose
to its tempfile. Sergio Gil -
Add
ActionController::StrongParameters
, this module convertsparams
hash into an instance of ActionController::Parameters that allows whitelisting of permitted parameters. Non-permitted parameters are forbidden to be used in Active Model by default For more details check the documentation of the module or the strong_parameters gemDHH + Guillermo Iguaran
-
Remove Integration between
attr_accessible
/attr_protected
andActionController::ParamsWrapper
. ParamWrapper now wraps all the parameters returned by the class method attribute_namesGuillermo Iguaran
-
Fix #7646, the log now displays the correct status code when an exception is raised.
Yves Senn
-
Allow pass couple extensions to
ActionView::Template.register_template_handler
call.Tima Maslyuchenko
-
Sprockets integration has been extracted from Action Pack to the
sprockets-rails
gem.rails
gem is depending onsprockets-rails
by default.Guillermo Iguaran
-
ActionDispatch::Session::MemCacheStore
now usesdalli
instead of the deprecatedmemcache-client
gem. As side effect the autoloading of unloaded classes objects saved as values in session isn't supported anymore when mem_cache session store is used, this can have an impact in apps only when config.cache_classes is false.Arun Agrawal + Guillermo Iguaran
-
Support multiple etags in If-None-Match header. Travis Warlick
-
Allow to configure how unverified request will be handled using
:with
option inprotect_from_forgery
method.Valid unverified request handling methods are:
:exception
- Raises ActionController::InvalidAuthenticityToken exception.:reset_session
- Resets the session.:null_session
- Provides an empty session during request but doesn't reset it completely. Used as default if:with
option is not specified.
New applications are generated with:
protect_from_forgery :with => :exception
Sergey Nartimov
-
Add .ruby template handler, this handler simply allows arbitrary Ruby code as a template. Guillermo Iguaran
-
Add
separator
option forActionView::Helpers::TextHelper#excerpt
:excerpt('This is a very beautiful morning', 'very', :separator => ' ', :radius => 1) # => ...a very beautiful...
Guirec Corbel
-
Added controller-level etag additions that will be part of the action etag computation Jeremy Kemper/DHH
class InvoicesController < ApplicationController etag { current_user.try :id } def show # Etag will differ even for the same invoice when it's viewed by a different current_user @invoice = Invoice.find(params[:id]) fresh_when(@invoice) end end
-
Add automatic template digests to all
CacheHelper#cache
calls (originally spiked in the cache_digests plugin) DHH -
When building a URL fails, add missing keys provided by Journey. Failed URL generation now returns a 500 status instead of a 404.
Richard Schneeman
-
Deprecate availbility of
ActionView::RecordIdentifier
in controllers by default. It's view specific and can be easily included in controller manually if someone really needs it. RecordIdentifier will be removed fromActionController::Base
in Rails 4.1. Piotr Sarnacki -
Fix
ActionView::RecordIdentifier
to work as a singleton. Piotr Sarnacki -
Deprecate
Template#mime_type
, it will be removed in Rails 4.1 in favor of#type
. Piotr Sarnacki -
Move vendored html-scanner from
action_controller
toaction_view
directory. If you require it directly, please use 'action_view/vendor/html-scanner', reference to 'action_controller/vendor/html-scanner' will be removed in Rails 4.1. Piot Sarnacki -
Fix handling of date selects when using both disabled and discard options. Fixes #7431.
Vasiliy Ermolovich
-
ActiveRecord::SessionStore
is extracted out of Rails into a gemactiverecord-session_store
. Settingconfig.session_store
to:active_record_store
will no longer work and will break if theactiverecord-session_store
gem isn't available. Prem Sichanugrist -
Fix
select_tag
whenoption_tags
is nil. Fixes #7404.Sandeep Ravichandran
-
Add
Request#formats=(extensions)
that lets you set multiple formats directly in a prioritized order.Example of using this for custom iphone views with an HTML fallback:
class ApplicationController < ActionController::Base before_filter :adjust_format_for_iphone_with_html_fallback private def adjust_format_for_iphone_with_html_fallback request.formats = [ :iphone, :html ] if request.env["HTTP_USER_AGENT"][/iPhone/] end end
DHH
-
Add Routing Concerns to declare common routes that can be reused inside others resources and routes.
Code before:
resources :messages do resources :comments end resources :posts do resources :comments resources :images, only: :index end
Code after:
concern :commentable do resources :comments end concern :image_attachable do resources :images, only: :index end resources :messages, concerns: :commentable resources :posts, concerns: [:commentable, :image_attachable]
DHH + Rafael Mendonça França
-
Add
start_hour
andend_hour
options to theselect_hour
helper. Evan Tann -
Raises an
ArgumentError
when the first argument inform_for
containnil
or is empty.Richard Schneeman
-
Add 'X-Frame-Options' => 'SAMEORIGIN' 'X-XSS-Protection' => '1; mode=block' and 'X-Content-Type-Options' => 'nosniff' as default headers.
Egor Homakov
-
Allow data attributes to be set as a first-level option for form_for, so you can write
form_for @record, data: { behavior: 'autosave' }
instead ofform_for @record, html: { data: { behavior: 'autosave' } }
DHH -
Deprecate
button_to_function
andlink_to_function
helpers.We recommend the use of Unobtrusive JavaScript instead. For example:
link_to "Greeting", "#", :class => "nav_link" $(function() { $('.nav_link').click(function() { // Some complex code return false; }); });
or
link_to "Greeting", '#', onclick: "alert('Hello world!'); return false", class: "nav_link"
for simple cases.
Rafael Mendonça França
-
javascript_include_tag :all
will now not includeapplication.js
if the file does not exists. Prem Sichanugrist -
Send an empty response body when call
head
with status between 100 and 199, 204, 205 or 304.Armand du Plessis
-
Fixed issue with where digest authentication would not work behind a proxy. Arthur Smith
-
Added
ActionController::Live
. Mix it in to your controller and you can stream data to the client live. For example:class FooController < ActionController::Base include ActionController::Live def index 100.times { # Client will see this as it's written response.stream.write "hello world\n" sleep 1 } response.stream.close end end
Aaron Patterson
-
Remove
ActionDispatch::Head
middleware in favor ofRack::Head
. Santiago Pastorino -
Deprecate
:confirm
in favor of:data => { :confirm => "Text" }
option forbutton_to
,button_tag
,image_submit_tag
,link_to
andsubmit_tag
helpers.Carlos Galdino + Rafael Mendonça França
-
Show routes in exception page while debugging a
RoutingError
in development. Richard Schneeman and Mattt Thompson -
Add
ActionController::Flash.add_flash_types
method to allow people to register their own flash types. e.g.:class ApplicationController add_flash_types :error, :warning end
If you add the above code, you can use
<%= error %>
in an erb, andredirect_to /foo, :error => 'message'
in a controller.kennyj
-
Remove Active Model dependency from Action Pack. Guillermo Iguaran
-
Support unicode characters in routes. Route will be automatically escaped, so instead of manually escaping:
get Rack::Utils.escape('こんにちは') => 'home#index'
You just have to write the unicode route:
get 'こんにちは' => 'home#index'
kennyj
-
Return proper format on exceptions. Santiago Pastorino
-
Allow to use
mounted_helpers
(helpers for accessing mounted engines) inActionView::TestCase
. Piotr Sarnacki -
Include
mounted_helpers
(helpers for accessing mounted engines) inActionDispatch::IntegrationTest
by default. Piotr Sarnacki -
Extracted redirect logic from
ActionController::ForceSSL::ClassMethods.force_ssl
intoActionController::ForceSSL#force_ssl_redirect
Jeremy Friesen
-
Make possible to use a block in
button_to
if the button text is hard to fit into the name parameter, e.g.:<%= button_to [:make_happy, @user] do %> Make happy <strong><%= @user.name %></strong> <% end %> # => "<form method="post" action="/users/1/make_happy" class="button_to"> # <div> # <button type="submit"> # Make happy <strong>Name</strong> # </button> # </div> # </form>"
Sergey Nartimov
-
change a way of ordering helpers from several directories. Previously, when loading helpers from multiple paths, all of the helpers files were gathered into one array an then they were sorted. Helpers from different directories should not be mixed before loading them to make loading more predictable. The most common use case for such behavior is loading helpers from engines. When you load helpers from application and engine Foo, in that order, first rails will load all of the helpers from application, sorted alphabetically and then it will do the same for Foo engine.
Piotr Sarnacki
-
truncate
now always returns an escaped HTML-safe string. The option:escape
can be used as false to not escape the result.Li Ellis Gallardo + Rafael Mendonça França
-
truncate
now accepts a block to show extra content when the text is truncated. Li Ellis Gallardo -
Add
week_field
,week_field_tag
,month_field
,month_field_tag
,datetime_local_field
,datetime_local_field_tag
,datetime_field
anddatetime_field_tag
helpers. Carlos Galdino -
Add
color_field
andcolor_field_tag
helpers. Carlos Galdino -
assert_generates
,assert_recognizes
, andassert_routing
all raiseAssertion
instead ofRoutingError
David Chelimsky -
URL path parameters with invalid encoding now raise ActionController::BadRequest. Andrew White
-
Malformed query and request parameter hashes now raise ActionController::BadRequest. Andrew White
-
Add
divider
option togrouped_options_for_select
to generate a separatoroptgroup
automatically, and deprecateprompt
as third argument, in favor of using an options hash. Nicholas Greenfield -
Add
time_field
andtime_field_tag
helpers which render aninput[type="time"]
tag. Alex Soulim -
Removed old text_helper apis for highlight, excerpt and word_wrap Jeremy Walker
-
Templates without a handler extension now raises a deprecation warning but still defaults to ERb. In future releases, it will simply return the template contents. Steve Klabnik
-
Deprecate
:disable_with
in favor of:data => { :disable_with => "Text" }
option fromsubmit_tag
,button_tag
andbutton_to
helpers.Carlos Galdino + Rafael Mendonça França
-
Remove
:mouseover
option fromimage_tag
helper. Rafael Mendonça França -
The
select
method (select tag) forces :include_blank ifrequired
is true anddisplay size
is one andmultiple
is not true. Angelo Capilleri -
Copy literal route constraints to defaults so that url generation know about them. The copied constraints are
:protocol
,:subdomain
,:domain
,:host
and:port
.Andrew White
-
respond_to
andrespond_with
now raise ActionController::UnknownFormat instead of directly returning head 406. The exception is rescued and converted to 406 in the exception handling middleware. Steven Soroka -
Allows
assert_redirected_to
to match against a regular expression. Andy Lindeman -
Add backtrace to development routing error page. Richard Schneeman
-
Replace
include_seconds
boolean argument with:include_seconds => true
option indistance_of_time_in_words
andtime_ago_in_words
signature. Dmitriy Kiriyenko -
Make current object and counter (when it applies) variables accessible when rendering templates with :object / :collection. Carlos Antonio da Silva
-
JSONP now uses mimetype text/javascript instead of application/json. omjokine
-
Allow to lazy load
default_form_builder
by passing aString
instead of a constant. Piotr Sarnacki -
Session arguments passed to
process
calls in functional tests are now merged into the existing session, whereas previously they would replace the existing session. This change may break some existing tests if they are asserting the exact contents of the session but should not break existing tests that only assert individual keys.Andrew White
-
Add
index
method to FormBuilder class. Jorge Bejar -
Remove the leading \n added by textarea on assert_select. Santiago Pastorino
-
Changed default value for
config.action_view.embed_authenticity_token_in_remote_forms
tofalse
. This change breaks remote forms that need to work also without javascript, so if you need such behavior, you can either set it totrue
or explicitly pass:authenticity_token => true
in form options -
Added ActionDispatch::SSL middleware that when included force all the requests to be under HTTPS protocol. Rafael Mendonça França
-
Add
include_hidden
option to select tag. With:include_hidden => false
select withmultiple
attribute doesn't generate hidden input with blank value. Vasiliy Ermolovich -
Removed default
size
option from thetext_field
,search_field
,telephone_field
,url_field
,email_field
helpers. Philip Arndt -
Removed default
cols
androws
options from thetext_area
helper. Philip Arndt -
Adds support for layouts when rendering a partial with a given collection. serabe
-
Allows the route helper
root
to take a string argument. For example,root 'pages#main'
. bcardarella -
Forms of persisted records use always PATCH (via the
_method
hack). fxn -
For resources, both PATCH and PUT are routed to the
update
action. fxn -
Don't ignore
force_ssl
in development. This is a change of behavior - use a:if
condition to recreate the old behavior.class AccountsController < ApplicationController force_ssl :if => :ssl_configured? def ssl_configured? !Rails.env.development? end end
Pat Allan
-
Adds support for the PATCH verb:
- Request objects respond to
patch?
. - Routes have a new
patch
method, and understand:patch
in the existing places where a verb is configured, like:via
. - New method
patch
available in functional tests. - If
:patch
is the default verb for updates, edits are tunneled as PATCH rather than as PUT, and routing acts accordingly. - New method
patch_via_redirect
available in integration tests.
dlee
- Request objects respond to
-
Integration tests support the
OPTIONS
method. Jeremy Kemper -
expires_in
accepts amust_revalidate
flag. If true, "must-revalidate" is added to the Cache-Control header. fxn -
Add
date_field
anddate_field_tag
helpers which render aninput[type="date"]
tag Olek Janiszewski -
Adds
image_url
,javascript_url
,stylesheet_url
,audio_url
,video_url
, andfont_url
to assets tag helper. These URL helpers will return the full path to your assets. This is useful when you are going to reference this asset from external host. Prem Sichanugrist -
Default responder will now always use your overridden block in
respond_with
to render your response. Prem Sichanugrist -
Allow
value_method
andtext_method
arguments fromcollection_select
andoptions_from_collection_for_select
to receive an object that responds to:call
, such as aproc
, to evaluate the option in the current element context. This works the same way withcollection_radio_buttons
andcollection_check_boxes
.Carlos Antonio da Silva + Rafael Mendonça França
-
Add
collection_check_boxes
form helper, similar tocollection_select
: Example:collection_check_boxes :post, :author_ids, Author.all, :id, :name # Outputs something like: <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" /> <label for="post_author_ids_1">D. Heinemeier Hansson</label> <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" /> <label for="post_author_ids_2">D. Thomas</label> <input name="post[author_ids][]" type="hidden" value="" />
The label/check_box pairs can be customized with a block.
Carlos Antonio da Silva + Rafael Mendonça França
-
Add
collection_radio_buttons
form helper, similar tocollection_select
: Example:collection_radio_buttons :post, :author_id, Author.all, :id, :name # Outputs something like: <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" /> <label for="post_author_id_1">D. Heinemeier Hansson</label> <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" /> <label for="post_author_id_2">D. Thomas</label>
The label/radio_button pairs can be customized with a block.
Carlos Antonio da Silva + Rafael Mendonça França
-
check_box with
:form
html5 attribute will now replicate the:form
attribute to the hidden field as well. Carlos Antonio da Silva -
Turn off verbose mode of rack-cache, we still have X-Rack-Cache to check that info. Closes #5245. Santiago Pastorino
-
label
form helper accepts :for => nil to not generate the attribute. Carlos Antonio da Silva -
Add
:format
option to number_to_percentage Rodrigo Flores -
Add
config.action_view.logger
to configure logger for Action View. Rafael Mendonça França -
Deprecated
ActionController::Integration
in favour ofActionDispatch::Integration
. -
Deprecated
ActionController::IntegrationTest
in favour ofActionDispatch::IntegrationTest
. -
Deprecated
ActionController::PerformanceTest
in favour ofActionDispatch::PerformanceTest
. -
Deprecated
ActionController::AbstractRequest
in favour ofActionDispatch::Request
. -
Deprecated
ActionController::Request
in favour ofActionDispatch::Request
. -
Deprecated
ActionController::AbstractResponse
in favour ofActionDispatch::Response
. -
Deprecated
ActionController::Response
in favour ofActionDispatch::Response
. -
Deprecated
ActionController::Routing
in favour ofActionDispatch::Routing
. -
check_box helper
with:disabled => true
will generate a disabled hidden field to conform with the HTML convention where disabled fields are not submitted with the form. This is a behavior change, previously the hidden tag had a value of the disabled checkbox. Tadas Tamosauskas -
favicon_link_tag
helper will now use the favicon in app/assets by default. Lucas Caton -
ActionView::Helpers::TextHelper#highlight
now defaults to the HTML5mark
element. Brian Cardarella
Please check 3-2-stable for previous changes.