Skip to content
This repository
tree: a4ff4fd2c3
Fetching contributors…

Cannot retrieve contributors at this time

file 1033 lines (972 sloc) 65.312 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>Ruby on Rails 2.3 Release Notes</title>
  <!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
<![endif]-->
  <link href="stylesheets/base.css" media="screen" rel="Stylesheet" type="text/css" />
  <link href="stylesheets/forms.css" media="screen" rel="Stylesheet" type="text/css" />
  <link href="stylesheets/more.css" media="screen" rel="Stylesheet" type="text/css" />
</head>
<body>
  <div id="header" >
    <div id="logo">
      <a href="index.html" title="Ruby on Rails"><img src="images/rails_logo_remix.gif" alt="Rails" height="140" width="110" /></a>
    </div>

    <h1 id="site_title"><span>Ruby on Rails</span></h1>
    <h2 id="site_title_tagline">Sustainable productivity for web-application development</h2>

    <ul id="navMain">
      <li class="first-child"><a href="http://www.rubyonrails.org/" title="Ruby on Rails" class="ruby_on_rails">Ruby on Rails</a></li>
      <li><a class="manuals" href="index.html" title="Manuals Index">Guides Index</a></li>
    </ul>
  </div>

  <div id="container">
    
    <div id="sidebar">
      <h2>Chapters</h2>
      <ol>
          <li>
          <a href="#_application_architecture">Application Architecture</a>
            <ul>
            
              <li><a href="#_rack_integration">Rack Integration</a></li>
            
              <li><a href="#_renewed_support_for_rails_engines">Renewed Support for Rails Engines</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_documentation">Documentation</a>
          </li>
          <li>
          <a href="#_active_record">Active Record</a>
            <ul>
            
              <li><a href="#_nested_attributes">Nested Attributes</a></li>
            
              <li><a href="#_nested_transactions">Nested Transactions</a></li>
            
              <li><a href="#_dynamic_scopes">Dynamic Scopes</a></li>
            
              <li><a href="#_default_scopes">Default Scopes</a></li>
            
              <li><a href="#_multiple_conditions_for_callbacks">Multiple Conditions for Callbacks</a></li>
            
              <li><a href="#_find_with_having">Find with having</a></li>
            
              <li><a href="#_hash_conditions_for_tt_has_many_tt_relationships">Hash Conditions for <tt>has_many</tt> relationships</a></li>
            
              <li><a href="#_reconnecting_mysql_connections">Reconnecting MySQL Connections</a></li>
            
              <li><a href="#_other_active_record_changes">Other Active Record Changes</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_action_controller">Action Controller</a>
            <ul>
            
              <li><a href="#_unified_rendering">Unified Rendering</a></li>
            
              <li><a href="#_application_controller_renamed">Application Controller Renamed</a></li>
            
              <li><a href="#_http_digest_authentication_support">HTTP Digest Authentication Support</a></li>
            
              <li><a href="#_more_efficient_routing">More Efficient Routing</a></li>
            
              <li><a href="#_rack_based_lazy_loaded_sessions">Rack-based Lazy-loaded Sessions</a></li>
            
              <li><a href="#_mime_type_handling_changes">MIME Type Handling Changes</a></li>
            
              <li><a href="#_optimization_of_tt_respond_to_tt">Optimization of <tt>respond_to</tt></a></li>
            
              <li><a href="#_improved_caching_performance">Improved Caching Performance</a></li>
            
              <li><a href="#_localized_views">Localized Views</a></li>
            
              <li><a href="#_other_action_controller_changes">Other Action Controller Changes</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_action_view">Action View</a>
            <ul>
            
              <li><a href="#_nested_object_forms">Nested Object Forms</a></li>
            
              <li><a href="#_smart_rendering_of_partials">Smart Rendering of Partials</a></li>
            
              <li><a href="#_prompts_for_date_select_helpers">Prompts for Date Select Helpers</a></li>
            
              <li><a href="#_assettag_timestamp_caching">AssetTag Timestamp Caching</a></li>
            
              <li><a href="#_asset_hosts_as_objects">Asset Hosts as Objects</a></li>
            
              <li><a href="#_grouped_options_for_select_helper_method">grouped_options_for_select Helper Method</a></li>
            
              <li><a href="#_other_action_view_changes">Other Action View Changes</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_active_support">Active Support</a>
            <ul>
            
              <li><a href="#_object_try">Object#try</a></li>
            
              <li><a href="#_object_tap_backport">Object#tap Backport</a></li>
            
              <li><a href="#_fractional_seconds_for_timewithzone">Fractional seconds for TimeWithZone</a></li>
            
              <li><a href="#_json_key_quoting">JSON Key Quoting</a></li>
            
              <li><a href="#_other_active_support_changes">Other Active Support Changes</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_railties">Railties</a>
            <ul>
            
              <li><a href="#_rails_metal">Rails Metal</a></li>
            
              <li><a href="#_application_templates">Application Templates</a></li>
            
              <li><a href="#_quieter_backtraces">Quieter Backtraces</a></li>
            
              <li><a href="#_faster_boot_time_in_development_mode_with_lazy_loading_autoload">Faster Boot Time in Development Mode with Lazy Loading/Autoload</a></li>
            
              <li><a href="#_other_railties_changes">Other Railties Changes</a></li>
            
            </ul>
          </li>
          <li>
          <a href="#_deprecated">Deprecated</a>
          </li>
          <li>
          <a href="#_credits">Credits</a>
          </li>
      </ol>
    </div>
    
    <div id="content">
        <h1>Ruby on Rails 2.3 Release Notes</h1>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn&#8217;t include every little bug fix and change. If you want to see everything, check out the <a href="http://github.com/rails/rails/commits/master">list of commits</a> in the main Rails repository on GitHub or review the <tt>CHANGELOG</tt> files for the individual Rails components.</p></div>
</div>
</div>
<h2 id="_application_architecture">1. Application Architecture</h2>
<div class="sectionbody">
<div class="paragraph"><p>There are two major changes in the architecture of Rails applications: complete integration of the <a href="http://rack.rubyforge.org/">Rack</a> modular web server interface, and renewed support for Rails Engines.</p></div>
<h3 id="_rack_integration">1.1. Rack Integration</h3>
<div class="paragraph"><p>Rails has now broken with its CGI past, and uses Rack everywhere. This required and resulted in a tremendous number of internal changes (but if you use CGI, don&#8217;t worry; Rails now supports CGI through a proxy interface.) Still, this is a major change to Rails internals. After upgrading to 2.3, you should test on your local environment and your production environment. Some things to test:</p></div>
<div class="ulist"><ul>
<li>
<p>
Sessions
</p>
</li>
<li>
<p>
Cookies
</p>
</li>
<li>
<p>
File uploads
</p>
</li>
<li>
<p>
JSON/XML APIs
</p>
</li>
</ul></div>
<div class="paragraph"><p>Here&#8217;s a summary of the rack-related changes:</p></div>
<div class="ulist"><ul>
<li>
<p>
<tt>script/server</tt> has been switched to use Rack, which means it supports any Rack compatible server. <tt>script/server</tt> will also pick up a rackup configuration file if one exists. By default, it will look for a <tt>config.ru</tt> file, but you can override this with the <tt>-c</tt> switch.
</p>
</li>
<li>
<p>
The FCGI handler goes through Rack
</p>
</li>
<li>
<p>
<tt>ActionController::Dispatcher</tt> maintains its own default middleware stack. Middlewares can be injected in, reordered, and removed. The stack is compiled into a chain on boot. You can configure the middleware stack in <tt>environment.rb</tt>
</p>
</li>
<li>
<p>
The <tt>rake middleware</tt> task has been added to inspect the middleware stack. This is useful for debugging the order of the middleware stack.
</p>
</li>
<li>
<p>
The integration test runner has been modified to execute the entire middleware and application stack. This makes integration tests perfect for testing Rack middleware.
</p>
</li>
<li>
<p>
<tt>ActionController::CGIHandler</tt> is a backwards compatible CGI wrapper around Rack. The <tt>CGIHandler</tt> is meant to take an old CGI object and converts its environment information into a Rack compatible form.
</p>
</li>
<li>
<p>
<tt>CgiRequest</tt> and <tt>CgiResponse</tt> have been removed
</p>
</li>
<li>
<p>
Session stores are now lazy loaded. If you never access the session object during a request, it will never attempt to load the session data (parse the cookie, load the data from memcache, or lookup an Active Record object).
</p>
</li>
<li>
<p>
<tt>CGI::Session::CookieStore</tt> has been replaced by <tt>ActionController::Session::CookieStore</tt>
</p>
</li>
<li>
<p>
<tt>CGI::Session::MemCacheStore</tt> has been replaced by <tt>ActionController::Session::MemCacheStore</tt>
</p>
</li>
<li>
<p>
<tt>CGI::Session::ActiveRecordStore</tt> has been replaced by <tt>ActiveRecord::SessionStore</tt>
</p>
</li>
<li>
<p>
You can still change your session store with <tt>ActionController::Base.session_store = :active_record_store</tt>
</p>
</li>
<li>
<p>
Default sessions options are still set with <tt>ActionController::Base.session = { :key =&gt; "..." }</tt>
</p>
</li>
<li>
<p>
The mutex that normally wraps your entire request has been moved into middleware, <tt>ActionController::Lock</tt>
</p>
</li>
<li>
<p>
<tt>ActionController::AbstractRequest</tt> and <tt>ActionController::Request</tt> have been unified. The new <tt>ActionController::Request</tt> inherits from <tt>Rack::Request</tt>. This affects access to <tt>response.headers[<em>type</em>]</tt> in test requests. Use <tt>response.content_type</tt> instead.
</p>
</li>
<li>
<p>
<tt>ActiveRecord::QueryCache</tt> middleware is automatically inserted onto the middleware stack if <tt>ActiveRecord</tt> has been loaded. This middleware sets up and flushes the per-request Active Record query cache.
</p>
</li>
<li>
<p>
The Rails router and controller classes follow the Rack spec. You can call a controller directly with <tt>SomeController.call(env)</tt>. The router stores the routing parameters in <tt>rack.routing_args</tt>.
</p>
</li>
<li>
<p>
<tt>ActionController::Request</tt> inherits from <tt>Rack::Request</tt>
</p>
</li>
<li>
<p>
Instead of <tt>config.action_controller.session = { :session_key =&gt; <em>foo</em>, ...</tt> use <tt>config.action_controller.session = { :key =&gt; <em>foo</em>, ...</tt>
</p>
</li>
<li>
<p>
Using the <tt>ParamsParser</tt> middleware preprocesses any XML, JSON, or YAML requests so they can be read normally with any <tt>Rack::Request</tt> object after it.
</p>
</li>
</ul></div>
<h3 id="_renewed_support_for_rails_engines">1.2. Renewed Support for Rails Engines</h3>
<div class="paragraph"><p>After some versions without an upgrade, Rails 2.3 offers some new features for Rails Engines (Rails applications that can be embedded within other applications). First, routing files in engines are automatically loaded and reloaded now, just like your <tt>routes.rb</tt> file (this also applies to routing files in other plugins). Second, if your plugin has an app folder, then app/[models|controllers|helpers] will automatically be added to the Rails load path. Engines also support adding view paths now.</p></div>
</div>
<h2 id="_documentation">2. Documentation</h2>
<div class="sectionbody">
<div class="paragraph"><p>The <a href="http://guides.rubyonrails.org/">Ruby on Rails guides</a> project has published several additional guides for Rails 2.3. In addition, a <a href="http://guides.rails.info/">separate site</a> maintains updated copies of the Guides for Edge Rails. Other documentation efforts include a relaunch of the <a href="http://newwiki.rubyonrails.org/">Rails wiki</a> and early planning for a Rails Book.</p></div>
<div class="ulist"><ul>
<li>
<p>
More Information: <a href="http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects">Rails Documentation Projects</a>
</p>
</li>
</ul></div>
</div>
<h2 id="_active_record">3. Active Record</h2>
<div class="sectionbody">
<div class="paragraph"><p>Active Record gets quite a number of new features and bug fixes in Rails 2.3. The highlights include nested attributes, nested transactions, dynamic scopes, and default scopes.</p></div>
<h3 id="_nested_attributes">3.1. Nested Attributes</h3>
<div class="paragraph"><p>Active Record can now update the attributes on nested models directly, provided you tell it to do so:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Book <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
  has_one <span style="color: #990000">:</span>author
  has_many <span style="color: #990000">:</span>pages

  accepts_nested_attributes_for <span style="color: #990000">:</span>author<span style="color: #990000">,</span> <span style="color: #990000">:</span>pages
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>Turning on nested attributes enables a number of things: automatic (and atomic) saving of a record together with its associated children, child-aware validations, and support for nested forms (discussed later).</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: link_to:<a href="http://www.superalloy.nl/blog/">Eloy Duran</a>
</p>
</li>
<li>
<p>
More Information: link_to:<a href="http://weblog.rubyonrails.org/2009/1/26/nested-model-forms">Nested Model Forms</a>
</p>
</li>
</ul></div>
<h3 id="_nested_transactions">3.2. Nested Transactions</h3>
<div class="paragraph"><p>Active Record now supports nested transactions, a much-requested feature. Now you can write code like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>User<span style="color: #990000">.</span>transaction <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>
    User<span style="color: #990000">.</span>create<span style="color: #990000">(:</span>username <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Admin'</span><span style="color: #990000">)</span>
    User<span style="color: #990000">.</span>transaction<span style="color: #990000">(:</span>requires_new <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span><span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span>
      User<span style="color: #990000">.</span>create<span style="color: #990000">(:</span>username <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Regular'</span><span style="color: #990000">)</span>
      <span style="font-weight: bold"><span style="color: #0000FF">raise</span></span> ActiveRecord<span style="color: #990000">::</span>Rollback
    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>

  User<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">)</span> <span style="font-style: italic"><span style="color: #9A1900"># =&gt; Returns only Admin</span></span></tt></pre></div></div>
<div class="paragraph"><p>Nested transactions let you roll back an inner transaction without affecting the state of the outer transaction. If you want a transaction to be nested, you must explicitly add the <tt>:requires_new</tt> option; otherwise, a nested transaction simply becomes part of the parent transaction (as it does currently on Rails 2.2). Under the covers, nested transactions are <a href="http://rails.lighthouseapp.com/projects/8994/tickets/383">using savepoints</a>, so they&#8217;re supported even on databases that don&#8217;t have true nested transactions. There is also a bit of magic going on to make these transactions play well with transactional fixtures during testing.</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributors: <a href="http://www.workingwithrails.com/person/4985-jonathan-viney">Jonathan Viney</a> and <a href="http://izumi.plan99.net/blog/">Hongli Lai</a>
</p>
</li>
</ul></div>
<h3 id="_dynamic_scopes">3.3. Dynamic Scopes</h3>
<div class="paragraph"><p>You know about dynamic finders in Rails (which allow you to concoct methods like <tt>find_by_color_and_flavor</tt> on the fly) and named scopes (which allow you to encapsulate reusable query conditions into friendly names like <tt>currently_active</tt>). Well, now you can have dynamic scope methods. The idea is to put together syntax that allows filtering on the fly <em>and</em> method chaining. For example:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>Order<span style="color: #990000">.</span>scoped_by_customer_id<span style="color: #990000">(</span><span style="color: #993399">12</span><span style="color: #990000">)</span>
Order<span style="color: #990000">.</span>scoped_by_customer_id<span style="color: #990000">(</span><span style="color: #993399">12</span><span style="color: #990000">).</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">,</span>
  <span style="color: #990000">:</span>conditions <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"status = 'open'"</span><span style="color: #990000">)</span>
Order<span style="color: #990000">.</span>scoped_by_customer_id<span style="color: #990000">(</span><span style="color: #993399">12</span><span style="color: #990000">).</span>scoped_by_status<span style="color: #990000">(</span><span style="color: #FF0000">"open"</span><span style="color: #990000">)</span></tt></pre></div></div>
<div class="paragraph"><p>There&#8217;s nothing to define to use dynamic scopes: they just work.</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://evilmartians.com/">Yaroslav Markin</a>
</p>
</li>
<li>
<p>
More Information: <a href="http://ryandaigle.com/articles/2008/12/29/what-s-new-in-edge-rails-dynamic-scope-methods">What&#8217;s New in Edge Rails: Dynamic Scope Methods</a>.
</p>
</li>
</ul></div>
<h3 id="_default_scopes">3.4. Default Scopes</h3>
<div class="paragraph"><p>Rails 2.3 will introduce the notion of <em>default scopes</em> similar to named scopes, but applying to all named scopes or find methods within the model. For example, you can write <tt>default_scope :order =&gt; <em>name ASC</em></tt> and any time you retrieve records from that model they&#8217;ll come out sorted by name (unless you override the option, of course).</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: Paweł Kondzior
</p>
</li>
<li>
<p>
More Information: <a href="http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping">What&#8217;s New in Edge Rails: Default Scoping</a>
</p>
</li>
</ul></div>
<h3 id="_multiple_conditions_for_callbacks">3.5. Multiple Conditions for Callbacks</h3>
<div class="paragraph"><p>When using Active Record callbacks, you can now combine <tt>:if</tt> and <tt>:unless</tt> options on the same callback, and supply multiple conditions as an array:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>before_save <span style="color: #990000">:</span>update_credit_rating<span style="color: #990000">,</span> <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>active<span style="color: #990000">,</span>
  <span style="color: #990000">:</span><span style="font-weight: bold"><span style="color: #0000FF">unless</span></span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">[:</span>admin<span style="color: #990000">,</span> <span style="color: #990000">:</span>cash_only<span style="color: #990000">]</span></tt></pre></div></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: L. Caviola
</p>
</li>
</ul></div>
<h3 id="_find_with_having">3.6. Find with having</h3>
<div class="paragraph"><p>Rails now has a <tt>:having</tt> option on find (as well as on <tt>has_many</tt> and <tt>has_and_belongs_to_many</tt> associations) for filtering records in grouped finds. As those with heavy SQL backgrounds know, this allows filtering based on grouped results:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>developers <span style="color: #990000">=</span> Developer<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">,</span> <span style="color: #990000">:</span>group <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"salary"</span><span style="color: #990000">,</span>
  <span style="color: #990000">:</span>having <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"sum(salary) &gt; 10000"</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>select <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"salary"</span><span style="color: #990000">)</span></tt></pre></div></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://github.com/miloops">Emilio Tagua</a>
</p>
</li>
</ul></div>
<h3 id="_hash_conditions_for_tt_has_many_tt_relationships">3.7. Hash Conditions for <tt>has_many</tt> relationships</h3>
<div class="paragraph"><p>You can once again use a hash in conditions for a <tt>has_many</tt> relationship:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>has_many <span style="color: #990000">:</span>orders<span style="color: #990000">,</span> <span style="color: #990000">:</span>conditions <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">{</span><span style="color: #990000">:</span>status <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'confirmed'</span><span style="color: #FF0000">}</span></tt></pre></div></div>
<div class="paragraph"><p>That worked in Rails 2.1, fails in Rails 2.2, and will now work again in Rails 2.3 (if you&#8217;re dealing with this issue in Rails 2.2, you can use a string rather than a hash to specify conditions).</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://www.spacevatican.org/">Frederick Cheung</a>
</p>
</li>
</ul></div>
<h3 id="_reconnecting_mysql_connections">3.8. Reconnecting MySQL Connections</h3>
<div class="paragraph"><p>MySQL supports a reconnect flag in its connections - if set to true, then the client will try reconnecting to the server before giving up in case of a lost connection. You can now set <tt>reconnect = true</tt> for your MySQL connections in <tt>database.yml</tt> to get this behavior from a Rails application. The default is <tt>false</tt>, so the behavior of existing applications doesn&#8217;t change.</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://twitter.com/dubek">Dov Murik</a>
</p>
</li>
<li>
<p>
More information:
</p>
<div class="ulist"><ul>
<li>
<p>
<a href="http://dev.mysql.com/doc/refman/5.0/en/auto-reconnect.html">Controlling Automatic Reconnection Behavior</a>
</p>
</li>
<li>
<p>
<a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/49d2a7e9c96cb9f4">MySQL auto-reconnect revisited</a>
</p>
</li>
</ul></div>
</li>
</ul></div>
<h3 id="_other_active_record_changes">3.9. Other Active Record Changes</h3>
<div class="ulist"><ul>
<li>
<p>
An extra <tt>AS</tt> was removed from the generated SQL for has_and_belongs_to_many preloading, making it work better for some databases.
</p>
</li>
<li>
<p>
<tt>ActiveRecord::Base#new_record?</tt> now returns false rather than nil when confronted with an existing record.
</p>
</li>
<li>
<p>
A bug in quoting table names in some <tt>has_many :through</tt> associations was fixed.
</p>
</li>
<li>
<p>
You can now specify a particular timestamp for <tt>updated_at</tt> timestamps: <tt>cust = Customer.create(:name =&gt; "ABC Industries", :updated_at =&gt; 1.day.ago)</tt>
</p>
</li>
<li>
<p>
Better error messages on failed <tt>find_by_attribute!</tt> calls.
</p>
</li>
<li>
<p>
Active Record&#8217;s <tt>to_xml</tt> support gets just a little bit more flexible with the addition of a <tt>:camelize</tt> option.
</p>
</li>
<li>
<p>
A bug in canceling callbacks from <tt>before_update</tt> or +before_create_ was fixed.
</p>
</li>
<li>
<p>
Rake tasks for testing databases via JDBC have been added.
</p>
</li>
<li>
<p>
<tt>validates_length_of</tt> will use a custom error message with the <tt>:in</tt> or <tt>:within</tt> options (if one is supplied)
</p>
</li>
</ul></div>
</div>
<h2 id="_action_controller">4. Action Controller</h2>
<div class="sectionbody">
<div class="paragraph"><p>Action Controller rolls out some significant changes to rendering, as well as improvements in routing and other areas, in this release.</p></div>
<h3 id="_unified_rendering">4.1. Unified Rendering</h3>
<div class="paragraph"><p><tt>ActionController::Base#render</tt> is a lot smarter about deciding what to render. Now you can just tell it what to render and expect to get the right results. In older versions of Rails, you often need to supply explicit information to render:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>render <span style="color: #990000">:</span>file <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'/tmp/random_file.erb'</span>
render <span style="color: #990000">:</span>template <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'other_controller/action'</span>
render <span style="color: #990000">:</span>action <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'show'</span></tt></pre></div></div>
<div class="paragraph"><p>Now in Rails 2.3, you can just supply what you want to render:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>render <span style="color: #FF0000">'/tmp/random_file.erb'</span>
render <span style="color: #FF0000">'other_controller/action'</span>
render <span style="color: #FF0000">'show'</span>
render <span style="color: #990000">:</span>show</tt></pre></div></div>
<div class="paragraph"><p>Rails chooses between file, template, and action depending on whether there is a leading slash, an embedded slash, or no slash at all in what&#8217;s to be rendered. Note that you can also use a symbol instead of a string when rendering an action. Other rendering styles (<tt>:inline</tt>, <tt>:text</tt>, <tt>:update</tt>, <tt>:nothing</tt>, <tt>:json</tt>, <tt>:xml</tt>, <tt>:js</tt>) still require an explicit option.</p></div>
<h3 id="_application_controller_renamed">4.2. Application Controller Renamed</h3>
<div class="paragraph"><p>If you&#8217;re one of the people who has always been bothered by the special-case naming of <tt>application.rb</tt>, rejoice! It&#8217;s been reworked to be application_controller.rb in Rails 2.3. In addition, there&#8217;s a new rake task, <tt>rake rails:update:application_controller</tt> to do this automatically for you - and it will be run as part of the normal <tt>rake rails:update</tt> process.</p></div>
<div class="ulist"><ul>
<li>
<p>
More Information:
</p>
<div class="ulist"><ul>
<li>
<p>
<a href="http://afreshcup.com/2008/11/17/rails-2x-the-death-of-applicationrb/">The Death of Application.rb</a>
</p>
</li>
<li>
<p>
<a href="http://ryandaigle.com/articles/2008/11/19/what-s-new-in-edge-rails-application-rb-duality-is-no-more">What&#8217;s New in Edge Rails: Application.rb Duality is no More</a>
</p>
</li>
</ul></div>
</li>
</ul></div>
<h3 id="_http_digest_authentication_support">4.3. HTTP Digest Authentication Support</h3>
<div class="paragraph"><p>Rails now has built-in support for HTTP digest authentication. To use it, you call <tt>authenticate_or_request_with_http_digest</tt> with a block that returns the user’s password (which is then hashed and compared against the transmitted credentials):</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> PostsController <span style="color: #990000">&lt;</span> ApplicationController
  Users <span style="color: #990000">=</span> <span style="color: #FF0000">{</span><span style="color: #FF0000">"dhh"</span> <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"secret"</span><span style="color: #FF0000">}</span>
  before_filter <span style="color: #990000">:</span>authenticate

  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> secret
    render <span style="color: #990000">:</span>text <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"Password Required!"</span>
  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>

  private
  <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> authenticate
    realm <span style="color: #990000">=</span> <span style="color: #FF0000">"Application"</span>
    authenticate_or_request_with_http_digest<span style="color: #990000">(</span>realm<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>name<span style="color: #990000">|</span>
      Users<span style="color: #990000">[</span>name<span style="color: #990000">]</span>
    <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
  <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://www.kellogg-assoc.com/">Gregg Kellogg</a>
</p>
</li>
<li>
<p>
More Information: <a href="http://ryandaigle.com/articles/2009/1/30/what-s-new-in-edge-rails-http-digest-authentication">What&#8217;s New in Edge Rails: HTTP Digest Authentication</a>
</p>
</li>
</ul></div>
<h3 id="_more_efficient_routing">4.4. More Efficient Routing</h3>
<div class="paragraph"><p>There are a couple of significant routing changes in Rails 2.3. The <tt>formatted_</tt> route helpers are gone, in favor just passing in <tt>:format</tt> as an option. This cuts down the route generation process by 50% for any resource - and can save a substantial amount of memory (up to 100MB on large applications). If your code uses the <tt>formatted_</tt> helpers, it will still work for the time being - but that behavior is deprecated and your application will be more efficient if you rewrite those routes using the new standard. Another big change is that Rails now supports multiple routing files, not just routes.rb. You can use <tt>RouteSet#add_configuration_file</tt> to bring in more routes at any time - without clearing the currently-loaded routes. While this change is most useful for Engines, you can use it in any application that needs to load routes in batches.</p></div>
<div class="paragraph"><p>Lead Contributors: <a href="http://blog.hungrymachine.com/">Aaron Batalion</a></p></div>
<h3 id="_rack_based_lazy_loaded_sessions">4.5. Rack-based Lazy-loaded Sessions</h3>
<div class="paragraph"><p>A big change pushed the underpinnings of Action Controller session storage down to the Rack level. This involved a good deal of work in the code, though it should be completely transparent to your Rails applications (as a bonus, some icky patches around the old CGI session handler got removed). It&#8217;s still significant, though, for one simple reason: non-Rails Rack applications have access to the same session storage handlers (and therefore the same session) as your Rails applications. In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). This means that you no longer need to explicitly disable sessions if you don&#8217;t want them; just don&#8217;t refer to them and they won&#8217;t load.</p></div>
<h3 id="_mime_type_handling_changes">4.6. MIME Type Handling Changes</h3>
<div class="paragraph"><p>There are a couple of changes to the code for handling MIME types in Rails. First, <tt>MIME::Type</tt> now implements the <tt>=~</tt> operator, making things much cleaner when you need to check for the presence of a type that has synonyms:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> content_type <span style="color: #990000">&amp;&amp;</span> Mime<span style="color: #990000">::</span>JS <span style="color: #990000">=~</span> content_type
  <span style="font-style: italic"><span style="color: #9A1900"># do something cool</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>

Mime<span style="color: #990000">::</span>JS <span style="color: #990000">=~</span> <span style="color: #FF0000">"text/javascript"</span> <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
Mime<span style="color: #990000">::</span>JS <span style="color: #990000">=~</span> <span style="color: #FF0000">"application/javascript"</span> <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span></tt></pre></div></div>
<div class="paragraph"><p>The other change is that the framework now uses the <tt>Mime::JS</tt> when checking for javascript in various spots, making it handle those alternatives cleanly.</p></div>
<div class="paragraph"><p>Lead Contributor: <a href="http://www.workingwithrails.com/person/5510-seth-fitzsimmons">Seth Fitzsimmons</a></p></div>
<h3 id="_optimization_of_tt_respond_to_tt">4.7. Optimization of <tt>respond_to</tt></h3>
<div class="paragraph"><p>In some of the first fruits of the Rails-Merb team merger, Rails 2.3 includes some optimizations for the <tt>respond_to</tt> method, which is of course heavily used in many Rails applications to allow your controller to format results differently based on the MIME type of the incoming request. After eliminating a call to <tt>method_missing</tt> and some profiling and tweaking, we&#8217;re seeing an 8% improvement in the number of requests per second served with a simple <tt>respond_to</tt> that switches between three formats. The best part? No change at all required to the code of your application to take advantage of this speedup.</p></div>
<h3 id="_improved_caching_performance">4.8. Improved Caching Performance</h3>
<div class="paragraph"><p>Rails now keeps a per-request local cache of requests, cutting down on unnecessary reads and leading to better site performance. While this work was originally limited to <tt>MemCacheStore</tt>, it is available to any remote store than implements the required methods.</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://www.motionstandingstill.com/">Nahum Wild</a>
</p>
</li>
</ul></div>
<h3 id="_localized_views">4.9. Localized Views</h3>
<div class="paragraph"><p>Rails can now provide localized views, depending on the locale that you have set. For example, suppose you have a <tt>Posts</tt> controller with a <tt>show</tt> action. By default, this will render <tt>app/views/posts/show.html.erb</tt>. But if you set <tt>I18n.locale = :da</tt>, it will render <tt>app/views/posts/show.da.html.erb</tt>. If the localized template isn&#8217;t present, the undecorated version will be used. Rails also includes <tt>I18n#available_locales</tt> and <tt>I18n::SimpleBackend#available_locales</tt>, which return an array of the translations that are available in the current Rails project.</p></div>
<h3 id="_other_action_controller_changes">4.10. Other Action Controller Changes</h3>
<div class="ulist"><ul>
<li>
<p>
ETag handling has been cleaned up a bit: Rails will now skip sending an ETag header when there&#8217;s no body to the response or when sending files with <tt>send_file</tt>.
</p>
</li>
<li>
<p>
The fact that Rails checks for IP spoofing can be a nuisance for sites that do heavy traffic with cell phones, because their proxies don&#8217;t generally set things up right. If that&#8217;s you, you can now set <tt>ActionController::Base.ip_spoofing_check = false</tt> to disable the check entirely.
</p>
</li>
<li>
<p>
<tt>ActionController::Dispatcher</tt> now implements its own middleware stack, which you can see by running <tt>rake middleware</tt>.
</p>
</li>
<li>
<p>
Cookie sessions now have persistent session identifiers, with API compatibility with the server-side stores.
</p>
</li>
<li>
<p>
You can now use symbols for the <tt>:type</tt> option of <tt>send_file</tt> and <tt>send_data</tt>, like this: <tt>send_file("fabulous.png", :type =&gt; :png)</tt>.
</p>
</li>
<li>
<p>
The <tt>:only</tt> and <tt>:except</tt> options for <tt>map.resources</tt> are no longer inherited by nested resources.
</p>
</li>
</ul></div>
</div>
<h2 id="_action_view">5. Action View</h2>
<div class="sectionbody">
<div class="paragraph"><p>Action View in Rails 2.3 picks up nested model forms, improvements to <tt>render</tt>, more flexible prompts for the date select helpers, and a speedup in asset caching, among other things.</p></div>
<h3 id="_nested_object_forms">5.1. Nested Object Forms</h3>
<div class="paragraph"><p>Provided the parent model accepts nested attributes for the child objects (as discussed in the Active Record section), you can create nested forms using <tt>form_for</tt> and <tt>field_for</tt>. These forms can be nested arbitrarily deep, allowing you to edit complex object hierarchies on a single view without excessive code. For example, given this model:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Customer <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
  has_many <span style="color: #990000">:</span>orders

  accepts_nested_attributes_for <span style="color: #990000">:</span>orders<span style="color: #990000">,</span> <span style="color: #990000">:</span>allow_destroy <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>You can write this view in Rails 2.3:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #FF0000">&lt;% form_for @customer do |customer_form| %&gt;</span>
  <span style="color: #FF0000">&lt;div&gt;</span>
    <span style="color: #FF0000">&lt;%= customer_form.label :name, 'Customer Name:' %&gt;</span>
    <span style="color: #FF0000">&lt;%= customer_form.text_field :name %&gt;</span>
  <span style="color: #FF0000">&lt;/div&gt;</span>

  <span style="color: #990000">&lt;!--</span> Here we call fields_for on the customer_form builder instance<span style="color: #990000">.</span>
       The block is called <span style="font-weight: bold"><span style="color: #0000FF">for</span></span> each member of the orders collection<span style="color: #990000">.</span> <span style="color: #990000">--&gt;</span>
  <span style="color: #FF0000">&lt;% customer_form.fields_for :orders do |order_form| %&gt;</span>
      <span style="color: #FF0000">&lt;p&gt;</span>
        <span style="color: #FF0000">&lt;div&gt;</span>
          <span style="color: #FF0000">&lt;%= order_form.label :number, 'Order Number:' %&gt;</span>
          <span style="color: #FF0000">&lt;%= order_form.text_field :number %&gt;</span>
        <span style="color: #FF0000">&lt;/div&gt;</span>

  <span style="color: #990000">&lt;!--</span> The allow_destroy option <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> the model enables deletion of
       child records<span style="color: #990000">.</span> <span style="color: #990000">--&gt;</span>
        <span style="color: #FF0000">&lt;% unless order_form.object.new_record? %&gt;</span>
          <span style="color: #FF0000">&lt;div&gt;</span>
            <span style="color: #FF0000">&lt;%= order_form.label :_delete, 'Remove:' %&gt;</span>
            <span style="color: #FF0000">&lt;%= order_form.check_box :_delete %&gt;</span>
          <span style="color: #FF0000">&lt;/div&gt;</span>
        <span style="color: #FF0000">&lt;% end %&gt;</span>
      <span style="color: #FF0000">&lt;/p&gt;</span>
    <span style="color: #FF0000">&lt;% end %&gt;</span>
  <span style="color: #FF0000">&lt;% end %&gt;</span>

  <span style="color: #FF0000">&lt;%= customer_form.submit %&gt;</span>
<span style="color: #FF0000">&lt;% end %&gt;</span></tt></pre></div></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: link_to:<a href="http://www.superalloy.nl/blog/">Eloy Duran</a>
</p>
</li>
<li>
<p>
More Information:
</p>
<div class="ulist"><ul>
<li>
<p>
link_to:<a href="http://weblog.rubyonrails.org/2009/1/26/nested-model-forms">Nested Model Forms</a>
</p>
</li>
<li>
<p>
link_to:<a href="http://github.com/alloy/complex-form-examples/tree/nested_attributes">complex-form-examples</a>
</p>
</li>
<li>
<p>
link_to:<a href="http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes">What&#8217;s New in Edge Rails: Nested Object Forms</a>
</p>
</li>
</ul></div>
</li>
</ul></div>
<h3 id="_smart_rendering_of_partials">5.2. Smart Rendering of Partials</h3>
<div class="paragraph"><p>The render method has been getting smarter over the years, and it&#8217;s even smarter now. If you have an object or a collection and an appropriate partial, and the naming matches up, you can now just render the object and things will work. For example, in Rails 2.3, these render calls will work in your view (assuming sensible naming):</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>render <span style="color: #009900">@article</span> <span style="font-style: italic"><span style="color: #9A1900"># Equivalent of render :partial =&gt; 'articles/_article', :object =&gt; @article</span></span>
render <span style="color: #009900">@articles</span> <span style="font-style: italic"><span style="color: #9A1900"># Equivalent of render :partial =&gt; 'articles/_article', :collection =&gt; @articles</span></span></tt></pre></div></div>
<div class="ulist"><ul>
<li>
<p>
More Information: <a href="http://ryandaigle.com/articles/2008/11/20/what-s-new-in-edge-rails-render-stops-being-high-maintenance">What&#8217;s New in Edge Rails: render Stops Being High-Maintenance</a>
</p>
</li>
</ul></div>
<h3 id="_prompts_for_date_select_helpers">5.3. Prompts for Date Select Helpers</h3>
<div class="paragraph"><p>In Rails 2.3, you can supply custom prompts for the various date select helpers (<tt>date_select</tt>, <tt>time_select</tt>, and <tt>datetime_select</tt>), the same way you can with collection select helpers. You can supply a prompt string or a hash of individual prompt strings for the various components. You can also just set <tt>:prompt</tt> to <tt>true</tt> to use the custom generic prompt:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>select_datetime<span style="color: #990000">(</span>DateTime<span style="color: #990000">.</span>now<span style="color: #990000">,</span> <span style="color: #990000">:</span>prompt <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span><span style="color: #990000">)</span>

select_datetime<span style="color: #990000">(</span>DateTime<span style="color: #990000">.</span>now<span style="color: #990000">,</span> <span style="color: #990000">:</span>prompt <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"Choose date and time"</span><span style="color: #990000">)</span>

select_datetime<span style="color: #990000">(</span>DateTime<span style="color: #990000">.</span>now<span style="color: #990000">,</span> <span style="color: #990000">:</span>prompt <span style="color: #990000">=&gt;</span>
  <span style="color: #FF0000">{</span><span style="color: #990000">:</span>day <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Choose day'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>month <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Choose month'</span><span style="color: #990000">,</span>
   <span style="color: #990000">:</span>year <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Choose year'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>hour <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Choose hour'</span><span style="color: #990000">,</span>
   <span style="color: #990000">:</span>minute <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'Choose minute'</span><span style="color: #FF0000">}</span><span style="color: #990000">)</span></tt></pre></div></div>
<div class="paragraph"><p>Lead Contributor: <a href="http://samoliver.com/">Sam Oliver</a></p></div>
<h3 id="_assettag_timestamp_caching">5.4. AssetTag Timestamp Caching</h3>
<div class="paragraph"><p>You&#8217;re likely familiar with Rails' practice of adding timestamps to static asset paths as a "cache buster." This helps ensure that stale copies of things like images and stylesheets don&#8217;t get served out of the user&#8217;s browser cache when you change them on the server. You can now modify this behavior with the <tt>cache_asset_timestamps</tt> configuration option for Action View. If you enable the cache, then Rails will calculate the timestamp once when it first serves an asset, and save that value. This means fewer (expensive) file system calls to serve static assets - but it also means that you can&#8217;t modify any of the assets while the server is running and expect the changes to get picked up by clients.</p></div>
<h3 id="_asset_hosts_as_objects">5.5. Asset Hosts as Objects</h3>
<div class="paragraph"><p>Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to to implement any complex logic you need in your asset hosting.</p></div>
<div class="ulist"><ul>
<li>
<p>
More Information: <a href="http://github.com/dhh/asset-hosting-with-minimum-ssl/tree/master">asset-hosting-with-minimum-ssl</a>
</p>
</li>
</ul></div>
<h3 id="_grouped_options_for_select_helper_method">5.6. grouped_options_for_select Helper Method</h3>
<div class="paragraph"><p>Action View already haD a bunch of helpers to aid in generating select controls, but now there&#8217;s one more: <tt>grouped_options_for_select</tt>. This one accepts an array or hash of strings, and converts them into a string of <tt>option</tt> tags wrapped with <tt>optgroup</tt> tags. For example:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>grouped_options_for_select<span style="color: #990000">([[</span><span style="color: #FF0000">"Hats"</span><span style="color: #990000">,</span> <span style="color: #990000">[</span><span style="color: #FF0000">"Baseball Cap"</span><span style="color: #990000">,</span><span style="color: #FF0000">"Cowboy Hat"</span><span style="color: #990000">]]],</span>
  <span style="color: #FF0000">"Cowboy Hat"</span><span style="color: #990000">,</span> <span style="color: #FF0000">"Choose a product..."</span><span style="color: #990000">)</span></tt></pre></div></div>
<div class="paragraph"><p>returns</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #FF0000">&lt;option value=""&gt;</span>Choose a product<span style="color: #990000">...</span><span style="color: #FF0000">&lt;/option&gt;</span>
<span style="color: #FF0000">&lt;optgroup label="Hats"&gt;</span>
  <span style="color: #FF0000">&lt;option value="Baseball Cap"&gt;</span>Baseball Cap<span style="color: #FF0000">&lt;/option&gt;</span>
  <span style="color: #FF0000">&lt;option selected="selected" value="Cowboy Hat"&gt;</span>Cowboy Hat<span style="color: #FF0000">&lt;/option&gt;</span>
<span style="color: #FF0000">&lt;/optgroup&gt;</span></tt></pre></div></div>
<h3 id="_other_action_view_changes">5.7. Other Action View Changes</h3>
<div class="ulist"><ul>
<li>
<p>
Token generation for CSRF protection has been simplified; now Rails uses a simple random string generated by <tt>ActiveSupport::SecureRandom</tt> rather than mucking around with session IDs.
</p>
</li>
<li>
<p>
<tt>auto_link</tt> now properly applies options (such as :target and :class) to generated e-mail links.
</p>
</li>
<li>
<p>
The <tt>autolink</tt> helper has been refactored to make it a bit less messy and more intuitive.
</p>
</li>
</ul></div>
</div>
<h2 id="_active_support">6. Active Support</h2>
<div class="sectionbody">
<div class="paragraph"><p>Active Support has a few interesting changes, including the introduction of <tt>Object#try</tt>.</p></div>
<h3 id="_object_try">6.1. Object#try</h3>
<div class="paragraph"><p>A lot of folks have adopted the notion of using try() to attempt operations on objects - It&#8217;s especially helpful in views where you can avoid nil-checking by writing code like <tt>&lt;%= @person.try(:name) %&gt;</tt>. Well, now it&#8217;s baked right into Rails. As implemented in Rails, it raises <tt>NoMethodError</tt> on private methods and always returns <tt>nil</tt> if the object is nil.</p></div>
<div class="ulist"><ul>
<li>
<p>
More Information: <a href="http://ozmm.org/posts/try.html">try()</a>.
</p>
</li>
</ul></div>
<h3 id="_object_tap_backport">6.2. Object#tap Backport</h3>
<div class="paragraph"><p><tt>Object#tap</tt> is an addition to "Ruby 1.9":http://www.ruby-doc.org/core-1.9/classes/Object.html#M000309 and 1.8.7 that is similar to the <tt>returning</tt> method that Rails has had for a while: it yields to a block, and then returns the object that was yielded. Rails now includes code to make this available under older versions of Ruby as well.</p></div>
<h3 id="_fractional_seconds_for_timewithzone">6.3. Fractional seconds for TimeWithZone</h3>
<div class="paragraph"><p>The <tt>Time</tt> and <tt>TimeWithZone</tt> classes include an <tt>xmlschema</tt> method to return the time in an XML-friendly string. As of Rails 2.3, <tt>TimeWithZone</tt> supports the same argument for specifying the number of digits in the fractional second part of the returned string that <tt>Time</tt> does:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #990000">&gt;&gt;</span> Time<span style="color: #990000">.</span>zone<span style="color: #990000">.</span>now<span style="color: #990000">.</span>xmlschema<span style="color: #990000">(</span><span style="color: #993399">6</span><span style="color: #990000">)</span>
<span style="color: #990000">=&gt;</span> <span style="color: #FF0000">"2009-01-16T13:00:06.13653Z"</span></tt></pre></div></div>
<div class="paragraph"><p>Lead Contributor: <a href="http://www.workingwithrails.com/person/13536-nicholas-dainty">Nicholas Dainty</a></p></div>
<h3 id="_json_key_quoting">6.4. JSON Key Quoting</h3>
<div class="paragraph"><p>If you look up the spec on the "json.org" site, you&#8217;ll discover that all keys in a JSON structure must be strings, and they must be quoted with double quotes. Starting with Rails 2.3, we doe the right thing here, even with numeric keys.</p></div>
<h3 id="_other_active_support_changes">6.5. Other Active Support Changes</h3>
<div class="ulist"><ul>
<li>
<p>
You can use <tt>Enumerable#none?</tt> to check that none of the elements match the supplied block.
</p>
</li>
<li>
<p>
If you&#8217;re using Active Support <a href="http://afreshcup.com/2008/10/19/coming-in-rails-22-delegate-prefixes/">delegates</a>, the new <tt>:allow_nil</tt> option lets you return nil instead of raising an exception when the target object is nil.
</p>
</li>
<li>
<p>
<tt>ActiveSupport::OrderedHash</tt>: now implements <tt>each_key</tt> and <tt>each_value</tt>.
</p>
</li>
<li>
<p>
<tt>ActiveSupport::MessageEncryptor</tt> provides a simple way to encrypt information for storage in an untrusted location (like cookies).
</p>
</li>
<li>
<p>
Active Support&#8217;s <tt>from_xml</tt> no longer depends on XmlSimple. Instead, Rails now includes its own XmlMini implementation, with just the functionality that it requires. This lets Rails dispense with the bundled copy of XmlSimple that it&#8217;s been carting around.
</p>
</li>
</ul></div>
</div>
<h2 id="_railties">7. Railties</h2>
<div class="sectionbody">
<div class="paragraph"><p>In addition to the Rack changes covered above, Railties (the core code of Rails itself) sports a number of significant changes, including Rails Metal, application templates, and quiet backtraces.</p></div>
<h3 id="_rails_metal">7.1. Rails Metal</h3>
<div class="paragraph"><p>Rails Metal is a new mechanism that provides superfast endpoints inside of your Rails applications. Metal classes bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack.</p></div>
<div class="ulist"><ul>
<li>
<p>
More Information:
</p>
<div class="ulist"><ul>
<li>
<p>
<a href="http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal">Introducing Rails Metal</a>
</p>
</li>
<li>
<p>
<a href="http://soylentfoo.jnewland.com/articles/2008/12/16/rails-metal-a-micro-framework-with-the-power-of-rails-m">Rails Metal: a micro-framework with the power of Rails</a>
</p>
</li>
<li>
<p>
<a href="http://www.railsinside.com/deployment/180-metal-super-fast-endpoints-within-your-rails-apps.html">Metal: Super-fast Endpoints within your Rails Apps</a>
</p>
</li>
<li>
<p>
<a href="http://ryandaigle.com/articles/2008/12/18/what-s-new-in-edge-rails-rails-metal">What&#8217;s New in Edge Rails: Rails Metal</a>
</p>
</li>
</ul></div>
</li>
</ul></div>
<h3 id="_application_templates">7.2. Application Templates</h3>
<div class="paragraph"><p>Rails 2.3 incorporates Jeremy McAnally&#8217;s <a href="http://github.com/jeremymcanally/rg/tree/master">rg</a> application generator. What this means is that we now have template-based application generation built right into Rails; if you have a set of plugins you include in every application (among many other use cases), you can just set up a template once and use it over and over again when you run the <tt>rails</tt> command. There&#8217;s also a rake task to apply a template to an existing application:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>rake rails<span style="color: #990000">:</span>template LOCATION<span style="color: #990000">=~/</span>template<span style="color: #990000">.</span>rb</tt></pre></div></div>
<div class="paragraph"><p>This will layer the changes from the template on top of whatever code the project already contains.</p></div>
<div class="ulist"><ul>
<li>
<p>
Lead Contributor: <a href="http://www.jeremymcanally.com/">Jeremy McAnally</a>
</p>
</li>
<li>
<p>
More Info:<a href="http://m.onkey.org/2008/12/4/rails-templates">Rails templates</a>
</p>
</li>
</ul></div>
<h3 id="_quieter_backtraces">7.3. Quieter Backtraces</h3>
<div class="paragraph"><p>Building on Thoughtbot&#8217;s <a href="http://www.thoughtbot.com/projects/quietbacktrace">Quiet Backtrace</a> plugin, which allows you to selectively remove lines from <tt>Test::Unit</tt> backtraces, Rails 2.3 implements <tt>ActiveSupport::BacktraceCleaner</tt> and <tt>Rails::BacktraceCleaner</tt> in core. This supports both filters (to perform regex-based substitutions on backtrace lines) and silencers (to remove backtrace lines entirely). Rails automatically adds silencers to get rid of the most common noise in a new application, and builds a <tt>config/backtrace_silencers.rb</tt> file to hold your own additions. This feature also enables prettier printing from any gem in the backtrace.</p></div>
<h3 id="_faster_boot_time_in_development_mode_with_lazy_loading_autoload">7.4. Faster Boot Time in Development Mode with Lazy Loading/Autoload</h3>
<div class="paragraph"><p>Quite a bit of work was done to make sure that bits of Rails (and its dependencies) are only brought into memory when they&#8217;re actually needed. The core frameworks - Active Support, Active Record, Action Controller, Action Mailer and Action View - are now using <tt>autoload</tt> to lazy-load their individual classes. This work should help keep the memory footprint down and improve overall Rails performance.</p></div>
<div class="paragraph"><p>You can also specify (by using the new <tt>preload_frameworks</tt> option) whether the core libraries should be autoloaded at startup. This defaults to <tt>false</tt> so that Rails autoloads itself piece-by-piece, but there are some circumstances where you still need to bring in everything at once - Passenger and JRuby both want to see all of Rails loaded together.</p></div>
<h3 id="_other_railties_changes">7.5. Other Railties Changes</h3>
<div class="ulist"><ul>
<li>
<p>
The instructions for updating a CI server to build Rails have been updated and expanded.
</p>
</li>
<li>
<p>
Internal Rails testing has been switched from <tt>Test::Unit::TestCase</tt> to <tt>ActiveSupport::TestCase</tt>, and the Rails core requires Mocha to test.
</p>
</li>
<li>
<p>
The default <tt>environment.rb</tt> file has been decluttered.
</p>
</li>
<li>
<p>
The dbconsole script now lets you use an all-numeric password without crashing.
</p>
</li>
<li>
<p>
Rails.root now returns a Pathname object, which means you can use it directly with the join method to <a href="http://afreshcup.com/2008/12/05/a-little-rails_root-tidiness/">clean up existing code</a> that uses File.join.
</p>
</li>
<li>
<p>
Various files in /public that deal with CGI and FCGI dispatching are no longer generated in every Rails application by default (you can still get them if you need them by adding <tt>--with-dispatches</tt> when you run the rails command, or add them later with <tt>rake rails:generate_dispatchers</tt>).
</p>
</li>
</ul></div>
</div>
<h2 id="_deprecated">8. Deprecated</h2>
<div class="sectionbody">
<div class="paragraph"><p>A few pieces of older code are deprecated in this release:</p></div>
<div class="ulist"><ul>
<li>
<p>
If you&#8217;re one of the (fairly rare) Rails developers who deploys in a fashion that depends on the inspector, reaper, and spawner scripts, you&#8217;ll need to know that those scripts are no longer included in core Rails. If you need them, you&#8217;ll be able to pick up copies via the <a href="http://github.com/rails/irs_process_scripts/tree">irs_process_scripts</a> plugin.
</p>
</li>
<li>
<p>
<tt>render_component</tt> goes from "deprecated" to "nonexistent" in Rails 2.3. If you still need it, you can install the <a href="http://github.com/rails/render_component/tree/master">render_component plugin</a>.
</p>
</li>
<li>
<p>
Support for Rails components has been removed.
</p>
</li>
<li>
<p>
If you were one of the people who got used to running <tt>script/performance/request</tt> to look at performance based on integration tests, you need to learn a new trick: that script has been removed from core Rails now. There’s a new request_profiler plugin that you can install to get the exact same functionality back.
</p>
</li>
<li>
<p>
<tt>ActionController::Base#session_enabled?</tt> is deprecated because sessions are lazy-loaded now.
</p>
</li>
<li>
<p>
The <tt>:digest</tt> and <tt>:secret</tt> options to <tt>protect_from_forgery</tt> are deprecated and have no effect.
</p>
</li>
<li>
<p>
Some integration test helpers have been removed. <tt>response.headers["Status"]</tt> and <tt>headers["Status"]</tt> will no longer return anything. Rack does not allow "Status" in its return headers. However you can still use the <tt>status</tt> and <tt>status_message</tt> helpers. <tt>response.headers["cookie"]</tt> and <tt>headers["cookie"]</tt> will no longer return any CGI cookies. You can inspect <tt>headers["Set-Cookie"]</tt> to see the raw cookie header or use the <tt>cookies</tt> helper to get a hash of the cookies sent to the client.
</p>
</li>
<li>
<p>
<tt>formatted_polymorphic_url</tt> is deprecated. Use <tt>polymorphic_url</tt> with <tt>:format</tt> instead.
</p>
</li>
</ul></div>
</div>
<h2 id="_credits">9. Credits</h2>
<div class="sectionbody">
<div class="paragraph"><p>Release notes compiled by <a href="http://afreshcup.com">Mike Gunderloy</a></p></div>
</div>

    </div>
  </div>
</body>
</html>
Something went wrong with that request. Please try again.