CHANGELOG.md 21.1 KB
Newer Older
1
## Rails 4.0.0 (unreleased) ##
J
José Valim 已提交
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
*   `assert_template` no more passing with what ever string that matches.
    
		Given Im rendering an template `/layout/hello.html.erb`, assert_template was
		passing with any string that matches. This behavior allowed false passing like:

		assert_template "layout"
		assert_template "out/hello"

		Now the passing possibilities are:

		assert_template "layout/hello"
		assert_template "hello"

    *Hugolnx*


19 20 21 22 23
*   `image_tag` will set the same width and height for image if numerical value
    passed to `size` option.

    *Nihad Abbasov*

24 25 26 27 28
*   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*

29 30
*   `ActionDispatch::Http::UploadedFile` now delegates `close` to its tempfile. *Sergio Gil*

31
*   Add `ActionController::StrongParameters`, this module converts `params` hash into
32
    an instance of ActionController::Parameters that allows whitelisting of permitted
33
    parameters. Non-permitted parameters are forbidden to be used in Active Model by default
34
    For more details check the documentation of the module or the
35 36 37 38 39
    [strong_parameters gem](https://github.com/rails/strong_parameters)

    *DHH + Guillermo Iguaran*

*   Remove Integration between `attr_accessible`/`attr_protected` and
40
    `ActionController::ParamsWrapper`. ParamWrapper now wraps all the parameters returned
41 42 43 44
    by the class method attribute_names

    *Guillermo Iguaran*

45 46 47 48
*   Fix #7646, the log now displays the correct status code when an exception is raised.

    *Yves Senn*

49 50 51
*   Allow pass couple extensions to `ActionView::Template.register_template_handler` call.

    *Tima Maslyuchenko*
52

53 54 55 56 57 58 59
*   Fixed a bug with shorthand routes scoped with the `:module` option not
    adding the module to the controller as described in issue #6497.
    This should now work properly:

        scope :module => "engine" do
          get "api/version" # routes to engine/api#version
        end
60

61 62
    *Luiz Felipe Garcia Pereira*

63
*   Sprockets integration has been extracted from Action Pack and the `sprockets-rails`
64
    gem should be added to Gemfile (under the assets group) in order to use Rails asset
65
    pipeline in future versions of Rails.
66 67 68

    *Guillermo Iguaran*

69 70 71 72
*   `ActionDispatch::Session::MemCacheStore` now uses `dalli` instead of the deprecated
    `memcache-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.
73 74 75

    *Arun Agrawal + Guillermo Iguaran*

76 77
*   Support multiple etags in If-None-Match header. *Travis Warlick*

S
Sergey Nartimov 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
*   Allow to configure how unverified request will be handled using `:with`
    option in `protect_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*

94
*   Add .ruby template handler, this handler simply allows arbitrary Ruby code as a template. *Guillermo Iguaran*
G
Guillermo Iguaran 已提交
95

96 97 98 99 100 101
*   Add `separator` option for `ActionView::Helpers::TextHelper#excerpt`:

        excerpt('This is a very beautiful morning', 'very', :separator  => ' ', :radius => 1)
        # => ...a very beautiful...

    *Guirec Corbel*
102

103 104
*   Added controller-level etag additions that will be part of the action etag computation *Jeremy Kemper/DHH*

105 106 107 108 109 110 111 112
        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
113 114
        end

115
*   Add automatic template digests to all `CacheHelper#cache` calls (originally spiked in the cache_digests plugin) *DHH*
116

117 118 119 120 121
*   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*

122
*   Deprecate availbility of `ActionView::RecordIdentifier` in controllers by default.
123
    It's view specific and can be easily included in controller manually if someone
124 125
    really needs it. RecordIdentifier will be removed from `ActionController::Base`
    in Rails 4.1. *Piotr Sarnacki*
126

127
*   Fix `ActionView::RecordIdentifier` to work as a singleton. *Piotr Sarnacki*
128

129
*   Deprecate `Template#mime_type`, it will be removed in Rails 4.1 in favor of `#type`.
130 131
    *Piotr Sarnacki*

132
*   Move vendored html-scanner from `action_controller` to `action_view` directory. If you
133
    require it directly, please use 'action_view/vendor/html-scanner', reference to
134
    'action_controller/vendor/html-scanner' will be removed in Rails 4.1. *Piot Sarnacki*
135

136 137 138 139 140
*   Fix handling of date selects when using both disabled and discard options.
    Fixes #7431.

    *Vasiliy Ermolovich*

141 142 143 144
*   `ActiveRecord::SessionStore` is extracted out of Rails into a gem `activerecord-session_store`.
    Setting `config.session_store` to `:active_record_store` will no longer work and will break
    if the `activerecord-session_store` gem isn't available. *Prem Sichanugrist*

145
*   Fix `select_tag` when `option_tags` is nil.
146 147 148 149
    Fixes #7404.

    *Sandeep Ravichandran*

150
*   Add `Request#formats=(extensions)` that lets you set multiple formats directly in a prioritized order.
151 152 153

    Example of using this for custom iphone views with an HTML fallback:

154 155 156 157 158 159 160 161
        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
162

163
    *DHH*
164

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
*   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]

193
    *DHH + Rafael Mendonça França*
194

195
*   Add `start_hour` and `end_hour` options to the `select_hour` helper. *Evan Tann*
196

197
*   Raises an `ArgumentError` when the first argument in `form_for` contain `nil`
198 199 200 201
    or is empty.

    *Richard Schneeman*

202 203 204
*   Add 'X-Frame-Options' => 'SAMEORIGIN'
    'X-XSS-Protection' => '1; mode=block' and
    'X-Content-Type-Options' => 'nosniff'
205 206 207 208
    as default headers.

    *Egor Homakov*

209 210
*   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 of `form_for @record, html: { data: { behavior: 'autosave' } }` *DHH*

211 212 213 214
*   Deprecate `button_to_function` and `link_to_function` helpers.

    We recommend the use of Unobtrusive JavaScript instead. For example:

215
        link_to "Greeting", "#", :class => "nav_link"
216

217 218 219
        $(function() {
          $('.nav_link').click(function() {
            // Some complex code
220

221 222
            return false;
          });
223 224 225 226
        });

    or

227
        link_to "Greeting", '#', onclick: "alert('Hello world!'); return false", class: "nav_link"
228 229 230 231 232

    for simple cases.

    *Rafael Mendonça França*

233 234
*   `javascript_include_tag :all` will now not include `application.js` if the file does not exists. *Prem Sichanugrist*

235 236 237 238
*   Send an empty response body when call `head` with status between 100 and 199, 204, 205 or 304.

    *Armand du Plessis*

239
*   Fixed issue with where digest authentication would not work behind a proxy. *Arthur Smith*
240

241
*   Added `ActionController::Live`.  Mix it in to your controller and you can
A
Aaron Patterson 已提交
242 243
    stream data to the client live.  For example:

244 245
        class FooController < ActionController::Base
          include ActionController::Live
A
Aaron Patterson 已提交
246

247 248 249 250 251 252 253 254
          def index
            100.times {
              # Client will see this as it's written
              response.stream.write "hello world\n"
              sleep 1
            }
            response.stream.close
          end
A
Aaron Patterson 已提交
255 256
        end

257 258 259
    *Aaron Patterson*

*   Remove `ActionDispatch::Head` middleware in favor of `Rack::Head`. *Santiago Pastorino*
S
Santiago Pastorino 已提交
260

261
*   Deprecate `:confirm` in favor of `:data => { :confirm => "Text" }` option for `button_to`, `button_tag`, `image_submit_tag`, `link_to` and `submit_tag` helpers.
262

263
    *Carlos Galdino + Rafael Mendonça França*
264

265
*   Show routes in exception page while debugging a `RoutingError` in development. *Richard Schneeman and Mattt Thompson*
266

K
kennyj 已提交
267 268 269 270 271 272
*   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

273
    If you add the above code, you can use `<%= error %>` in an erb, and `redirect_to /foo, :error => 'message'` in a controller.
K
kennyj 已提交
274 275 276

    *kennyj*

277 278
*   Remove Active Model dependency from Action Pack. *Guillermo Iguaran*

279 280 281 282 283 284 285 286 287 288
*   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*

289 290
*   Return proper format on exceptions. *Santiago Pastorino*

291
*   Allow to use `mounted_helpers` (helpers for accessing mounted engines) in `ActionView::TestCase`. *Piotr Sarnacki*
292

293
*   Include `mounted_helpers` (helpers for accessing mounted engines) in `ActionDispatch::IntegrationTest` by default. *Piotr Sarnacki*
294

295 296 297 298
*   Extracted redirect logic from `ActionController::ForceSSL::ClassMethods.force_ssl`  into `ActionController::ForceSSL#force_ssl_redirect`

    *Jeremy Friesen*

299
*   Make possible to use a block in `button_to` if the button text is hard
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
    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*

315 316 317 318 319 320 321 322 323 324 325
*   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*

326
*   `truncate` now always returns an escaped HTML-safe string. The option `:escape` can be used as
327 328 329 330
    false to not escape the result.

    *Li Ellis Gallardo + Rafael Mendonça França*

331 332
*   `truncate` now accepts a block to show extra content when the text is truncated. *Li Ellis Gallardo*

C
Carlos Galdino 已提交
333 334 335
*   Add `week_field`, `week_field_tag`, `month_field`, `month_field_tag`, `datetime_local_field`,
    `datetime_local_field_tag`, `datetime_field` and `datetime_field_tag` helpers. *Carlos Galdino*

336 337
*   Add `color_field` and `color_field_tag` helpers. *Carlos Galdino*

338 339 340
*   `assert_generates`, `assert_recognizes`, and `assert_routing` all raise
    `Assertion` instead of `RoutingError` *David Chelimsky*

341 342
*   URL path parameters with invalid encoding now raise ActionController::BadRequest. *Andrew White*

343 344
*   Malformed query and request parameter hashes now raise ActionController::BadRequest. *Andrew White*

345 346 347 348
*   Add `divider` option to `grouped_options_for_select` to generate a separator
    `optgroup` automatically, and deprecate `prompt` as third argument, in favor
    of using an options hash. *Nicholas Greenfield*

349 350
*   Add `time_field` and `time_field_tag` helpers which render an `input[type="time"]` tag. *Alex Soulim*

351 352
*   Removed old text_helper apis for highlight, excerpt and word_wrap *Jeremy Walker*

J
José Valim 已提交
353 354 355
*   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*

356
*   Deprecate `:disable_with` in favor of `:data => { :disable_with => "Text" }` option from `submit_tag`, `button_tag` and `button_to` helpers.
357 358 359

    *Carlos Galdino + Rafael Mendonça França*

360 361 362
*   Remove `:mouseover` option from `image_tag` helper. *Rafael Mendonça França*

*   The `select` method (select tag) forces :include_blank  if `required` is true and
363 364
    `display size` is one and `multiple` is not true. *Angelo Capilleri*

365 366 367 368 369
*   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*

J
José Valim 已提交
370 371 372 373
*   `respond_to` and `respond_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*

374 375
*   Allows `assert_redirected_to` to match against a regular expression. *Andy Lindeman*

S
Santiago Pastorino 已提交
376 377
*   Add backtrace to development routing error page. *Richard Schneeman*

378 379 380
*   Replace `include_seconds` boolean argument with `:include_seconds => true` option
    in `distance_of_time_in_words` and `time_ago_in_words` signature. *Dmitriy Kiriyenko*

381 382 383
*   Make current object and counter (when it applies) variables accessible when
    rendering templates with :object / :collection. *Carlos Antonio da Silva*

J
Jo Liss 已提交
384
*   JSONP now uses mimetype text/javascript instead of application/json. *omjokine*
385

386 387
*   Allow to lazy load `default_form_builder` by passing a `String` instead of a constant. *Piotr Sarnacki*

388 389 390 391 392 393 394
*   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*

395 396
*   Add `index` method to FormBuilder class. *Jorge Bejar*

397 398
*   Remove the leading \n added by textarea on assert_select. *Santiago Pastorino*

399 400 401 402 403
*   Changed default value for `config.action_view.embed_authenticity_token_in_remote_forms`
    to `false`. This change breaks remote forms that need to work also without javascript,
    so if you need such behavior, you can either set it to `true` or explicitly pass
    `:authenticity_token => true` in form options

404 405
*   Added ActionDispatch::SSL middleware that when included force all the requests to be under HTTPS protocol. *Rafael Mendonça França*

406
*   Add `include_hidden` option to select tag. With `:include_hidden => false` select with `multiple` attribute doesn't generate hidden input with blank value. *Vasiliy Ermolovich*
407

408 409 410 411
*   Removed default `size` option from the `text_field`, `search_field`, `telephone_field`, `url_field`, `email_field` helpers. *Philip Arndt*

*   Removed default `cols` and `rows` options from the `text_area` helper. *Philip Arndt*

412
*   Adds support for layouts when rendering a partial with a given collection. *serabe*
413

414
*   Allows the route helper `root` to take a string argument. For example, `root 'pages#main'`. *bcardarella*
415

416
*   Forms of persisted records use always PATCH (via the `_method` hack). *fxn*
417

418
*   For resources, both PATCH and PUT are routed to the `update` action. *fxn*
419

420 421 422 423 424 425 426 427 428 429 430 431
*   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*

432 433 434 435 436 437 438 439 440 441 442
*   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*

443 444
*   Integration tests support the `OPTIONS` method. *Jeremy Kemper*

445 446 447
*   `expires_in` accepts a `must_revalidate` flag. If true, "must-revalidate"
    is added to the Cache-Control header. *fxn*

448 449
*   Add `date_field` and `date_field_tag` helpers which render an `input[type="date"]` tag *Olek Janiszewski*

450 451 452 453
*   Adds `image_url`, `javascript_url`, `stylesheet_url`, `audio_url`, `video_url`, and `font_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*

454 455
*   Default responder will now always use your overridden block in `respond_with` to render your response. *Prem Sichanugrist*

456 457 458 459 460 461 462 463 464 465
*   Allow `value_method` and `text_method` arguments from `collection_select` and
    `options_from_collection_for_select` to receive an object that responds to `:call`,
    such as a `proc`, to evaluate the option in the current element context. This works
    the same way with `collection_radio_buttons` and `collection_check_boxes`.

    *Carlos Antonio da Silva + Rafael Mendonça França*

*   Add `collection_check_boxes` form helper, similar to `collection_select`:
    Example:

466 467 468 469 470 471 472
        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="" />
473 474 475 476 477 478 479 480

    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 to `collection_select`:
    Example:

481 482 483 484 485 486
        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>
487 488 489 490 491

    The label/radio_button pairs can be customized with a block.

    *Carlos Antonio da Silva + Rafael Mendonça França*

492 493 494
*   check_box with `:form` html5 attribute will now replicate the `:form`
    attribute to the hidden field as well. *Carlos Antonio da Silva*

495 496 497
*   Turn off verbose mode of rack-cache, we still have X-Rack-Cache to
    check that info. Closes #5245. *Santiago Pastorino*

498 499
*   `label` form helper accepts :for => nil to not generate the attribute. *Carlos Antonio da Silva*

500 501
*   Add `:format` option to number_to_percentage *Rodrigo Flores*

502
*   Add `config.action_view.logger` to configure logger for Action View. *Rafael Mendonça França*
503

504
*   Deprecated `ActionController::Integration` in favour of `ActionDispatch::Integration`.
505

506
*   Deprecated `ActionController::IntegrationTest` in favour of `ActionDispatch::IntegrationTest`.
507

508
*   Deprecated `ActionController::PerformanceTest` in favour of `ActionDispatch::PerformanceTest`.
509

510
*   Deprecated `ActionController::AbstractRequest` in favour of `ActionDispatch::Request`.
511

512
*   Deprecated `ActionController::Request` in favour of `ActionDispatch::Request`.
513

514
*   Deprecated `ActionController::AbstractResponse` in favour of `ActionDispatch::Response`.
515

516
*   Deprecated `ActionController::Response` in favour of `ActionDispatch::Response`.
517

518
*   Deprecated `ActionController::Routing` in favour of `ActionDispatch::Routing`.
519

520 521 522 523
*   `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*
524

525 526
*   `favicon_link_tag` helper will now use the favicon in app/assets by default. *Lucas Caton*

527 528
*   `ActionView::Helpers::TextHelper#highlight` now defaults to the
    HTML5 `mark` element. *Brian Cardarella*
529

X
Xavier Noria 已提交
530
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionpack/CHANGELOG.md) for previous changes.