From 56221faecdb47163cb463531506821aa6ba50370 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Sat, 1 Jan 2011 17:54:02 +0100 Subject: [PATCH 01/26] Added support for generating translated guides (stored in `source/`) via setting the LANG environment variable --- railties/guides/rails_guides/generator.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 68d406e31c..e4f9ea4916 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -38,6 +38,10 @@ # Note that if you are working on a guide generation will by default process # only that one, so ONLY is rarely used nowadays. # +# LANG +# Use LANG when you want to generate translated guides in source/ +# folder (such as source/es). Ignore it when generating English guides. +# # EDGE # Set to "1" to indicate generated guides should be marked as edge. This # inserts a badge and changes the preamble of the home page. @@ -63,6 +67,7 @@ module RailsGuides GUIDES_RE = /\.(?:textile|html\.erb)$/ def initialize(output=nil) + @lang = ENV['LANG'] initialize_dirs(output) create_output_dir_if_needed set_flags_from_environment @@ -76,8 +81,8 @@ module RailsGuides private def initialize_dirs(output) @guides_dir = File.join(File.dirname(__FILE__), '..') - @source_dir = File.join(@guides_dir, "source") - @output_dir = output || File.join(@guides_dir, "output") + @source_dir = File.join(@guides_dir, "source", @lang.to_s) + @output_dir = output || File.join(@guides_dir, "output", @lang.to_s) end def create_output_dir_if_needed From 1f8ecb85d7c1b3efdf45c3cf3461502b608c1a7c Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 2 Jan 2011 03:35:38 +0700 Subject: [PATCH 02/26] Update CHANGELOGs to include 3.0.3 changes --- actionmailer/CHANGELOG | 12 ++++++++++-- actionpack/CHANGELOG | 12 +++++++++++- activemodel/CHANGELOG | 7 ++++++- activerecord/CHANGELOG | 10 +++++++++- activeresource/CHANGELOG | 10 +++++++++- activesupport/CHANGELOG | 10 +++++++++- railties/CHANGELOG | 12 ++++++++++++ 7 files changed, 66 insertions(+), 7 deletions(-) diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index 167c1da9c5..b500718476 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -2,14 +2,22 @@ * No changes -*Rails 3.0.2 (unreleased)* -* No changes +*Rails 3.0.3 (November 16, 2010)* + +* No changes. + + +*Rails 3.0.2 (November 15, 2010)* + +* No changes. + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * subject is automatically looked up on I18n using mailer_name and action_name as scope as in t(".subject") [JK] diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 78fadce6cb..c237530c0e 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -33,14 +33,24 @@ * Add Rack::Cache to the default stack. Create a Rails store that delegates to the Rails cache, so by default, whatever caching layer you are using will be used for HTTP caching. Note that Rack::Cache will be used if you use #expires_in, #fresh_when or #stale with :public => true. Otherwise, the caching rules will apply to the browser only. [Yehuda Katz, Carl Lerche] -*Rails 3.0.2 (unreleased)* + +*Rails 3.0.3 (November 16, 2010)* + +* When ActiveRecord::Base objects are sent to predicate methods, the id of the object should be sent to ARel, not the ActiveRecord::Base object. + +* :constraints routing should only do sanity checks against regular expressions. String arguments are OK. + + +*Rails 3.0.2 (November 15, 2010)* * The helper number_to_currency accepts a new :negative_format option to be able to configure how to render negative amounts. [Don Wilson] + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * password_field renders with nil value by default making the use of passwords secure by default, if you want to render you should do for instance f.password_field(:password, :value => @user.password) [Santiago Pastorino] diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG index 9dd5e03685..ea91c97ba2 100644 --- a/activemodel/CHANGELOG +++ b/activemodel/CHANGELOG @@ -3,7 +3,12 @@ * Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting [DHH] -*Rails 3.0.2 (unreleased)* +*Rails 3.0.3 (November 16, 2010)* + +* No changes. + + +*Rails 3.0.2 (November 15, 2010)* * No changes diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 8ebc87145c..da4bd4f1cb 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -103,7 +103,13 @@ IrreversibleMigration exception will be raised when going down. [Aaron Patterson] -*Rails 3.0.2 (unreleased)* + +*Rails 3.0.3 (November 16, 2010)* + +* Support find by class like this: Post.where(:name => Post) + + +*Rails 3.0.2 (November 15, 2010)* * reorder is deprecated in favor of except(:order).order(...) [Santiago Pastorino] @@ -132,10 +138,12 @@ IrreversibleMigration exception will be raised when going down. [Aaron Patterson] + *Rails 3.0.1 (October 15, 2010)* * Introduce a fix for CVE-2010-3993 + *Rails 3.0.0 (August 29, 2010)* * Changed update_attribute to not run callbacks and update the record directly in the database [Neeraj Singh] diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index 386bafd7de..e9fd772d0c 100644 --- a/activeresource/CHANGELOG +++ b/activeresource/CHANGELOG @@ -2,14 +2,22 @@ * No changes -*Rails 3.0.2 (unreleased)* + +*Rails 3.0.3 (November 16, 2010)* * No changes + +*Rails 3.0.2 (November 15, 2010)* + +* No changes + + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * JSON: set Base.include_root_in_json = true to include a root value in the JSON: {"post": {"title": ...}}. Mirrors the Active Record option. [Santiago Pastorino] diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 6e8cce0d27..58cfc86c41 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -4,14 +4,22 @@ * Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! [Andrew White] -*Rails 3.0.2 (unreleased)* + +*Rails 3.0.3 (November 16, 2010)* + +* No changes. + + +*Rails 3.0.2 (November 15, 2010)* * Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! [Andrew White] + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * Implemented String#strip_heredoc. [fxn] diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 75f1df44e7..2db2c5c89d 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -26,10 +26,22 @@ * Include all helpers from plugins and shared engines in application [Piotr Sarnacki] + +*Rails 3.0.3 (November 16, 2010)* + +* No changes. + + +*Rails 3.0.2 (November 15, 2010)* + +* No changes. + + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn] From ebb732a7ecc0502299ee5948c31f536c3d6ef15c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 2 Jan 2011 02:53:15 +0530 Subject: [PATCH 03/26] fix typos --- railties/guides/source/routing.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index f60d72352d..1d81c8f95b 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -498,7 +498,7 @@ You specify a request-based constraint the same way that you specify a segment c match "photos", :constraints => {:subdomain => "admin"} -You can also specify constrains in a block form: +You can also specify constraints in a block form: namespace :admin do @@ -598,7 +598,7 @@ You can specify what Rails should route +"/"+ to with the +root+ method: root :to => 'pages#main' -You should put the +root+ route at the end of the file. You also need to delete the public/index.html.erb file for the root route to take effect. +You should put the +root+ route at the end of the file. You also need to delete the +public/index.html+ file for the root route to take effect. h3. Customizing Resourceful Routes @@ -633,7 +633,7 @@ You can use the +:constraints+ option to specify a required format on the implic resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/} -This declaration constrains the +:id+ parameter to match the supplied regular expression. So, in this case, the router would no longer match +/photos/1+ to this route. Instead, +/photos/RR27+ would match. +This declaration constraints the +:id+ parameter to match the supplied regular expression. So, in this case, the router would no longer match +/photos/1+ to this route. Instead, +/photos/RR27+ would match. You can specify a single constraint to apply to a number of routes by using the block form: From 99424eb0996d41eaccb1b140cc30820fb5779fef Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 2 Jan 2011 00:20:59 +0100 Subject: [PATCH 04/26] Revert "Update CHANGELOGs to include 3.0.3 changes" Reason: Sorry, CHANGELOGs can only be edited in master. If you provide a patch I'll apply it myself. Thanks! This reverts commit 1f8ecb85d7c1b3efdf45c3cf3461502b608c1a7c. --- actionmailer/CHANGELOG | 12 ++---------- actionpack/CHANGELOG | 12 +----------- activemodel/CHANGELOG | 7 +------ activerecord/CHANGELOG | 10 +--------- activeresource/CHANGELOG | 10 +--------- activesupport/CHANGELOG | 10 +--------- railties/CHANGELOG | 12 ------------ 7 files changed, 7 insertions(+), 66 deletions(-) diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG index b500718476..167c1da9c5 100644 --- a/actionmailer/CHANGELOG +++ b/actionmailer/CHANGELOG @@ -2,22 +2,14 @@ * No changes +*Rails 3.0.2 (unreleased)* -*Rails 3.0.3 (November 16, 2010)* - -* No changes. - - -*Rails 3.0.2 (November 15, 2010)* - -* No changes. - +* No changes *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. - *Rails 3.0.0 (August 29, 2010)* * subject is automatically looked up on I18n using mailer_name and action_name as scope as in t(".subject") [JK] diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c237530c0e..78fadce6cb 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -33,24 +33,14 @@ * Add Rack::Cache to the default stack. Create a Rails store that delegates to the Rails cache, so by default, whatever caching layer you are using will be used for HTTP caching. Note that Rack::Cache will be used if you use #expires_in, #fresh_when or #stale with :public => true. Otherwise, the caching rules will apply to the browser only. [Yehuda Katz, Carl Lerche] - -*Rails 3.0.3 (November 16, 2010)* - -* When ActiveRecord::Base objects are sent to predicate methods, the id of the object should be sent to ARel, not the ActiveRecord::Base object. - -* :constraints routing should only do sanity checks against regular expressions. String arguments are OK. - - -*Rails 3.0.2 (November 15, 2010)* +*Rails 3.0.2 (unreleased)* * The helper number_to_currency accepts a new :negative_format option to be able to configure how to render negative amounts. [Don Wilson] - *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. - *Rails 3.0.0 (August 29, 2010)* * password_field renders with nil value by default making the use of passwords secure by default, if you want to render you should do for instance f.password_field(:password, :value => @user.password) [Santiago Pastorino] diff --git a/activemodel/CHANGELOG b/activemodel/CHANGELOG index ea91c97ba2..9dd5e03685 100644 --- a/activemodel/CHANGELOG +++ b/activemodel/CHANGELOG @@ -3,12 +3,7 @@ * Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting [DHH] -*Rails 3.0.3 (November 16, 2010)* - -* No changes. - - -*Rails 3.0.2 (November 15, 2010)* +*Rails 3.0.2 (unreleased)* * No changes diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index da4bd4f1cb..8ebc87145c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -103,13 +103,7 @@ IrreversibleMigration exception will be raised when going down. [Aaron Patterson] - -*Rails 3.0.3 (November 16, 2010)* - -* Support find by class like this: Post.where(:name => Post) - - -*Rails 3.0.2 (November 15, 2010)* +*Rails 3.0.2 (unreleased)* * reorder is deprecated in favor of except(:order).order(...) [Santiago Pastorino] @@ -138,12 +132,10 @@ IrreversibleMigration exception will be raised when going down. [Aaron Patterson] - *Rails 3.0.1 (October 15, 2010)* * Introduce a fix for CVE-2010-3993 - *Rails 3.0.0 (August 29, 2010)* * Changed update_attribute to not run callbacks and update the record directly in the database [Neeraj Singh] diff --git a/activeresource/CHANGELOG b/activeresource/CHANGELOG index e9fd772d0c..386bafd7de 100644 --- a/activeresource/CHANGELOG +++ b/activeresource/CHANGELOG @@ -2,22 +2,14 @@ * No changes - -*Rails 3.0.3 (November 16, 2010)* +*Rails 3.0.2 (unreleased)* * No changes - -*Rails 3.0.2 (November 15, 2010)* - -* No changes - - *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. - *Rails 3.0.0 (August 29, 2010)* * JSON: set Base.include_root_in_json = true to include a root value in the JSON: {"post": {"title": ...}}. Mirrors the Active Record option. [Santiago Pastorino] diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 58cfc86c41..6e8cce0d27 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -4,22 +4,14 @@ * Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! [Andrew White] - -*Rails 3.0.3 (November 16, 2010)* - -* No changes. - - -*Rails 3.0.2 (November 15, 2010)* +*Rails 3.0.2 (unreleased)* * Added before_remove_const callback to ActiveSupport::Dependencies.remove_unloadable_constants! [Andrew White] - *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. - *Rails 3.0.0 (August 29, 2010)* * Implemented String#strip_heredoc. [fxn] diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 2db2c5c89d..75f1df44e7 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -26,22 +26,10 @@ * Include all helpers from plugins and shared engines in application [Piotr Sarnacki] - -*Rails 3.0.3 (November 16, 2010)* - -* No changes. - - -*Rails 3.0.2 (November 15, 2010)* - -* No changes. - - *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. - *Rails 3.0.0 (August 29, 2010)* * Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn] From a388c10f96a32d5be6154b813662f1a085ec23f1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 3 Jan 2011 02:01:04 +0530 Subject: [PATCH 05/26] Fix typos and JavaScript case. --- railties/guides/source/ajax_on_rails.textile | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/railties/guides/source/ajax_on_rails.textile b/railties/guides/source/ajax_on_rails.textile index 972e7ea840..3d7fcdc198 100644 --- a/railties/guides/source/ajax_on_rails.textile +++ b/railties/guides/source/ajax_on_rails.textile @@ -1,10 +1,10 @@ h2. AJAX on Rails -This guide covers the built-in Ajax/Javascript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics: +This guide covers the built-in Ajax/JavaScript functionality of Rails (and more); it will enable you to create rich and dynamic AJAX applications with ease! We will cover the following topics: * Quick introduction to AJAX and related technologies -* Handling Javascript the Rails way: Rails helpers, RJS, Prototype and script.aculo.us -* Testing Javascript functionality +* Handling JavaScript the Rails way: Rails helpers, RJS, Prototype and script.aculo.us +* Testing JavaScript functionality endprologue. @@ -12,7 +12,7 @@ h3. Hello AJAX - a Quick Intro If you are a 'show me the code' type of person, you might want to skip this part and jump to the RJS section right away. However, I would really recommend to read it - you'll need the basics of DOM, http requests and other topics discussed here to really understand Ajax on Rails. -h4. Asynchronous Javascript + XML +h4. Asynchronous JavaScript + XML Basic terminology, new style of creating web apps @@ -31,7 +31,7 @@ How do 'standard' and AJAX requests differ, why does this matter for understandi h3. Built-in Rails Helpers -Rails' Javascript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose Javascript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other Javascript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. +Rails' JavaScript framework of choice is "Prototype":http://www.prototypejs.org. Prototype is a generic-purpose JavaScript framework that aims to ease the development of dynamic web applications by offering DOM manipulation, AJAX and other JavaScript functionality ranging from utility functions to object oriented constructs. It is not specifically written for any language, so Rails provides a set of helpers to enable seamless integration of Prototype with your Rails views. To get access to these helpers, all you have to do is to include the prototype framework in your pages - typically in your master layout, application.html.erb - like so: @@ -136,7 +136,7 @@ link_to_remote "Add new item", :before => "$('progress').show()", :complete => "$('progress').hide()", :success => "display_item_added(request)", - :failure => "display_error(request)", + :failure => "display_error(request)" ** *:type* If you want to fire a synchronous request for some obscure reason (blocking the browser while the request is processed and doesn't return a status code), you can use the +:type+ option with the value of +:synchronous+. * Finally, using the +html_options+ parameter you can add HTML attributes to the generated tag. It works like the same parameter of the +link_to+ helper. There are interesting side effects for the +href+ and +onclick+ parameters though: @@ -153,7 +153,7 @@ There are three different ways of adding AJAX forms to your view using Rails Pro * +form_remote_tag+ AJAXifies the form by serializing and sending it's data in the background * +submit_to_remote+ and +button_to_remote+ is more rarely used than the previous two. Rather than creating an AJAX form, you add a button/input -Let's se them in action one by one! +Let's see them in action one by one! h5. +remote_form_for+ @@ -183,7 +183,7 @@ h3. JavaScript the Rails way: RJS In the last section we sent some AJAX requests to the server, and inserted the HTML response into the page (with the +:update+ option). However, sometimes a more complicated interaction with the page is needed, which you can either achieve with JavaScript... or with RJS! You are sending JavaScript instructions to the server in both cases, but while in the former case you have to write vanilla JavaScript, in the second you can code Rails, and sit back while Rails generates the JavaScript for you - so basically RJS is a Ruby DSL to write JavaScript in your Rails code. -h4. Javascript without RJS +h4. JavaScript without RJS First we'll check out how to send JavaScript to the server manually. You are practically never going to need this, but it's interesting to understand what's going on under the hood. @@ -329,9 +329,9 @@ h4. Drag and Drop -h3. Testing Javascript +h3. Testing JavaScript -Javascript testing reminds me the definition of the world 'classic' by Mark Twain: "A classic is something that everybody wants to have read and nobody wants to read." It's similar with Javascript testing: everyone would like to have it, yet it's not done by too much developers as it is tedious, complicated, there is a proliferation of tools and no consensus/accepted best practices, but we will nevertheless take a stab at it: +JavaScript testing reminds me the definition of the world 'classic' by Mark Twain: "A classic is something that everybody wants to have read and nobody wants to read." It's similar with JavaScript testing: everyone would like to have it, yet it's not done by too much developers as it is tedious, complicated, there is a proliferation of tools and no consensus/accepted best practices, but we will nevertheless take a stab at it: * (Fire)Watir * Selenium @@ -339,4 +339,4 @@ Javascript testing reminds me the definition of the world 'classic' by Mark Twai * Cucumber+Webrat * Mention stuff like screw.unit/jsSpec -Note to self: check out the RailsConf JS testing video \ No newline at end of file +Note to self: check out the RailsConf JS testing video From 1877faa7ac2053628b63a665ab822e18f2939a83 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Sun, 2 Jan 2011 22:09:09 +0100 Subject: [PATCH 06/26] [FIX] Renamed ENV['LANG'] for generating translated guides to ENV['LANGUAGE'] so there's no mixup with OS env vars --- railties/guides/rails_guides/generator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index e4f9ea4916..154355cac1 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -38,8 +38,8 @@ # Note that if you are working on a guide generation will by default process # only that one, so ONLY is rarely used nowadays. # -# LANG -# Use LANG when you want to generate translated guides in source/ +# LANGUAGE +# Use LANGUAGE when you want to generate translated guides in source/ # folder (such as source/es). Ignore it when generating English guides. # # EDGE @@ -67,7 +67,7 @@ module RailsGuides GUIDES_RE = /\.(?:textile|html\.erb)$/ def initialize(output=nil) - @lang = ENV['LANG'] + @lang = ENV['LANGUAGE'] initialize_dirs(output) create_output_dir_if_needed set_flags_from_environment From 75bfb4761c21a8f97f6c1780855f811adcc4c1c8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 6 Jan 2011 03:24:34 +0530 Subject: [PATCH 07/26] fixes rubycentral url and a minor AR change --- railties/lib/rails/generators/rails/app/templates/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/generators/rails/app/templates/README b/railties/lib/rails/generators/rails/app/templates/README index fe7013d52d..9f0f1d0e38 100644 --- a/railties/lib/rails/generators/rails/app/templates/README +++ b/railties/lib/rails/generators/rails/app/templates/README @@ -91,7 +91,7 @@ mode. With gems, use sudo gem install ruby-debug. Example: class WeblogController < ActionController::Base def index - @posts = Post.find(:all) + @posts = Post.all debugger end end @@ -139,7 +139,7 @@ To reload your controllers and models after launching the console run reload! More information about irb can be found at: -link:http://www.rubycentral.com/pickaxe/irb.html +link:http://www.rubycentral.org/pickaxe/irb.html == dbconsole From 27717655ad7ab4549a5799285975e425e8f80b15 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 3 Jan 2011 12:00:14 +1000 Subject: [PATCH 08/26] Re-add "Using initializer files" section to configuring guide --- railties/guides/source/configuring.textile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 6e72ae6ead..a3da5e93f1 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -397,6 +397,15 @@ Some parts of Rails can also be configured externally by supplying environment v * +ENV["RAILS_CACHE_ID"]+ and +ENV["RAILS_APP_VERSION"]+ are used to generate expanded cache keys in Rails' caching code. This allows you to have multiple separate caches from the same application. + +h3. Using Initializer Files + +After loading the framework and any gems and plugins in your application, Rails turns to loading initializers. An initializer is any file of Ruby code stored under +config/initializers+ in your application. You can use initializers to hold configuration settings that should be made after all of the frameworks, plugins and gems are loaded, such as options to configure settings for these parts. + +NOTE: You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the initializers folder on down. + +TIP: If you have any ordering dependency in your initializers, you can control the load order by naming. For example, +01_critical.rb+ will be loaded before +02_normal.rb+. + h3. Initialization events Rails has 5 initialization events which can be hooked into (listed in order that they are ran): From a41d33431fa19a08aec52030aeb7225fefe7aa47 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 3 Jan 2011 12:04:21 +1000 Subject: [PATCH 09/26] config guide: add basic description for disable_dependency_loading initializer --- railties/guides/source/configuring.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index a3da5e93f1..eee18f1131 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -560,8 +560,7 @@ TIP: If you have any ordering dependency in your initializers, you can control t *+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+. -*+disable_dependency_loading+* - +*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to +true+ and +config.dependency_loading+ is set to +false+. h3. Changelog From f612069ae157ba4312672d59dd844a01197cac9e Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 6 Jan 2011 20:06:52 +1000 Subject: [PATCH 10/26] Fix documentation for validates_uniqueness_of to NOT have a :scope argument as the prime example. Show scope examples after prime example. --- .../lib/active_record/validations/uniqueness.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index 853808eebf..e6a2b40403 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -85,11 +85,16 @@ module ActiveRecord # can be named "davidhh". # # class Person < ActiveRecord::Base - # validates_uniqueness_of :user_name, :scope => :account_id + # validates_uniqueness_of :user_name # end # - # It can also validate whether the value of the specified attributes are unique based on multiple - # scope parameters. For example, making sure that a teacher can only be on the schedule once + # It can also validate whether the value of the specified attributes are unique based on a scope parameter: + # + # class Person < ActiveRecord::Base + # validates_uniqueness_of :user_name, :scope => :account_id + # end + # + # Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once # per semester for a particular class. # # class TeacherSchedule < ActiveRecord::Base From bc6e1a154a2df3096d36ed3612b0b93c0a466728 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 8 Jan 2011 23:35:36 +0530 Subject: [PATCH 11/26] fix template url --- railties/guides/source/generators.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 4fec1760c4..3adbbfa7aa 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -396,7 +396,7 @@ This command will generate the +Thud+ application, and then apply the template t Templates don't have to be stored on the local system, the +-m+ option also supports online templates: - rails new thud -m https://gist.github.com/722911 + rails new thud -m https://gist.github.com/722911.txt Whilst the final section of this guide doesn't cover how to generate the most awesome template known to man, it will take you through the methods available at your disposal so that you can develop it yourself. These same methods are also available for generators. From 4d29816fdad8bd8ed8eb98f12fda6a7b107cc7f4 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 9 Jan 2011 02:24:30 +0530 Subject: [PATCH 12/26] fixed query output --- railties/guides/source/active_record_querying.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 6e45bf3188..22358029d4 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -440,7 +440,7 @@ And this will give you a single +Order+ object for each date where there are ord The SQL that would be executed would be something like this: -SELECT * FROM orders GROUP BY date(created_at) +SELECT * FROM orders GROUP BY date(created_at) ORDER BY created_at h3. Having @@ -664,7 +664,7 @@ Eager loading is the mechanism for loading the associated records of the objects Consider the following code, which finds 10 clients and prints their postcodes: -clients = Client.all(:limit => 10) +clients = Client.limit(10) clients.each do |client| puts client.address.postcode From 726a66a7a46c1274a3a1ff45b589952252749ebe Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Sun, 9 Jan 2011 10:00:15 -0800 Subject: [PATCH 13/26] Expand and clarify AS::Callbacks docs. --- activesupport/lib/active_support/callbacks.rb | 228 +++++++++--------- 1 file changed, 115 insertions(+), 113 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 32ebea8571..f79363d953 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -5,27 +5,28 @@ require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/kernel/singleton_class' module ActiveSupport - # Callbacks are hooks into the life cycle of an object that allow you to trigger logic - # before or after an alteration of the object state. + # \Callbacks are code hooks that are run at key points in an object's lifecycle. + # The typical use case is to have a base class define a set of callbacks relevant + # to the other functionality it supplies, so that subclasses can install callbacks + # that enhance or modify the base functionality without needing to override + # or redefine methods of the base class. # - # Mixing in this module allows you to define callbacks in your class. + # Mixing in this module allows you to define the events in the object's lifecycle + # that will support callbacks (via +ClassMethods.define_callbacks+), set the instance + # methods, procs, or callback objects to be called (via +ClassMethods.set_callback+), + # and run the installed callbacks at the appropriate times (via +run_callbacks+). # - # Example: - # class Storage + # Three kinds of callbacks are supported: before callbacks, run before a certain event; + # after callbacks, run after the event; and around callbacks, blocks that surround the + # event, triggering it when they yield. Callback code can be contained in instance + # methods, procs or lambdas, or callback objects that respond to certain predetermined + # methods. See +ClassMethods.set_callback+ for details. + # + # ==== Example + # + # class Record # include ActiveSupport::Callbacks - # # define_callbacks :save - # end - # - # class ConfigStorage < Storage - # set_callback :save, :before, :saving_message - # def saving_message - # puts "saving..." - # end - # - # set_callback :save, :after do |object| - # puts "saved" - # end # # def save # run_callbacks :save do @@ -34,29 +35,7 @@ module ActiveSupport # end # end # - # config = ConfigStorage.new - # config.save - # - # Output: - # saving... - # - save - # saved - # - # Callbacks from parent classes are inherited. - # - # Example: - # class Storage - # include ActiveSupport::Callbacks - # - # define_callbacks :save - # - # set_callback :save, :before, :prepare - # def prepare - # puts "preparing save" - # end - # end - # - # class ConfigStorage < Storage + # class PersonRecord < Record # set_callback :save, :before, :saving_message # def saving_message # puts "saving..." @@ -65,19 +44,12 @@ module ActiveSupport # set_callback :save, :after do |object| # puts "saved" # end - # - # def save - # run_callbacks :save do - # puts "- save" - # end - # end # end # - # config = ConfigStorage.new - # config.save + # person = PersonRecord.new + # person.save # # Output: - # preparing save # saving... # - save # saved @@ -89,11 +61,25 @@ module ActiveSupport extend ActiveSupport::DescendantsTracker end + # Runs the callbacks for the given event. + # + # Calls the before and around callbacks in the order they were set, yields + # the block (if given one), and then runs the after callbacks in reverse order. + # Optionally accepts a key, which will be used to compile an optimized callback + # method for each key. See +ClassMethods.define_callbacks+ for more information. + # + # If the callback chain was halted, returns +false+. Otherwise returns the result + # of the block, or +true+ if no block is given. + # + # run_callbacks :save do + # save + # end + # def run_callbacks(kind, *args, &block) send("_run_#{kind}_callbacks", *args, &block) end - class Callback + class Callback #:nodoc:# @@_callback_sequence = 0 attr_accessor :chain, :filter, :kind, :options, :per_key, :klass, :raw_filter @@ -328,7 +314,7 @@ module ActiveSupport end # An Array with a compile method - class CallbackChain < Array + class CallbackChain < Array #:nodoc:# attr_reader :name, :config def initialize(name, config) @@ -373,18 +359,7 @@ module ActiveSupport end module ClassMethods - # Make the run_callbacks :save method. The generated method takes - # a block that it'll yield to. It'll call the before and around filters - # in order, yield the block, and then run the after filters. - # - # run_callbacks :save do - # save - # end - # - # The run_callbacks :save method can optionally take a key, which - # will be used to compile an optimized callback method for each - # key. See #define_callbacks for more information. - # + # Generate the internal runner method called by +run_callbacks+. def __define_runner(symbol) #:nodoc: body = send("_#{symbol}_callbacks").compile @@ -440,18 +415,42 @@ module ActiveSupport end end - # Set callbacks for a previously defined callback. + # Install a callback for the given event. # - # Syntax: # set_callback :save, :before, :before_meth # set_callback :save, :after, :after_meth, :if => :condition # set_callback :save, :around, lambda { |r| stuff; yield; stuff } # - # If the second argument is not :before, :after or :around then an implicit :before is assumed. - # It means the first example mentioned above can also be written as: + # The second arguments indicates whether the callback is to be run +:before+, + # +:after+, or +:around+ the event. If omitted, +:before+ is assumed. This + # means the first example above can also be written as: + # # set_callback :save, :before_meth # - # Use skip_callback to skip any defined one. + # The callback can specified as a symbol naming an instance method; as a proc, + # lambda, or block; as a string to be instance evaluated; or as an object that + # responds to a certain method determined by the :scope argument to + # +define_callback+. + # + # If a proc, lambda, or block is given, its body is evaluated in the context + # of the current object. It can also optionally accept the current object as + # an argument. + # + # Before and around callbacks are called in the order that they are set; after + # callbacks are called in the reverse order. + # + # ===== Options + # + # * :if - A symbol naming an instance method or a proc; the callback + # will be called only when it returns a true value. + # * :unless - A symbol naming an instance method or a proc; the callback + # will be called only when it returns a false value. + # * :prepend - If true, the callback will be prepended to the existing + # chain rather than appended. + # * :per_key - A hash with :if and :unless options; + # see "Per-key conditions" below. + # + # ===== Per-key conditions # # When creating or skipping callbacks, you can specify conditions that # are always the same for a given key. For instance, in Action Pack, @@ -463,7 +462,7 @@ module ActiveSupport # # set_callback :process_action, :before, :authenticate, :per_key => {:unless => proc {|c| c.action_name == "index"}} # - # Per-Key conditions are evaluated only once per use of a given key. + # Per-key conditions are evaluated only once per use of a given key. # In the case of the above example, you would do: # # run_callbacks(:process_action, action_name) { ... dispatch stuff ... } @@ -490,7 +489,8 @@ module ActiveSupport end end - # Skip a previously defined callback. + # Skip a previously set callback. Like +set_callback+, :if or :unless + # options may be passed in order to control when the callback is skipped. # # class Writer < Person # skip_callback :validate, :before, :check_membership, :if => lambda { self.age > 18 } @@ -513,7 +513,7 @@ module ActiveSupport end end - # Reset callbacks for a given type. + # Remove all set callbacks for the given event. # def reset_callbacks(symbol) callbacks = send("_#{symbol}_callbacks") @@ -530,68 +530,70 @@ module ActiveSupport __define_runner(symbol) end - # Defines callbacks types: + # Define sets of events in the object lifecycle that support callbacks. # # define_callbacks :validate + # define_callbacks :initialize, :save, :destroy # - # This macro accepts the following options: + # ===== Options # - # * :terminator - Indicates when a before filter is considered - # to halted. This is a string to be eval'ed and has the result of the - # very filter available in the result variable: + # * :terminator - Determines when a before filter will halt the callback + # chain, preventing following callbacks from being called and the event from being + # triggered. This is a string to be eval'ed. The result of the callback is available + # in the result variable. # - # define_callbacks :validate, :terminator => "result == false" + # define_callbacks :validate, :terminator => "result == false" # - # In the example above, if any before validate callbacks returns +false+, - # other callbacks are not executed. Defaults to "false", meaning no value - # halts the chain. + # In this example, if any before validate callbacks returns +false+, + # other callbacks are not executed. Defaults to "false", meaning no value + # halts the chain. # # * :rescuable - By default, after filters are not executed if - # the given block or a before filter raises an error. Set this option to - # true to change this behavior. + # the given block or a before filter raises an error. Set this option to + # true to change this behavior. # - # * :scope - Indicates which methods should be executed when a class - # is given as callback. Defaults to [:kind]. + # * :scope - Indicates which methods should be executed when an object + # is used as a callback. # - # class Audit - # def before(caller) - # puts 'Audit: before is called' - # end + # class Audit + # def before(caller) + # puts 'Audit: before is called' + # end # - # def before_save(caller) - # puts 'Audit: before_save is called' - # end - # end + # def before_save(caller) + # puts 'Audit: before_save is called' + # end + # end # - # class Account - # include ActiveSupport::Callbacks + # class Account + # include ActiveSupport::Callbacks # - # define_callbacks :save - # set_callback :save, :before, Audit.new + # define_callbacks :save + # set_callback :save, :before, Audit.new # - # def save - # run_callbacks :save do - # puts 'save in main' - # end - # end - # end + # def save + # run_callbacks :save do + # puts 'save in main' + # end + # end + # end # - # In the above case whenever you save an account the method Audit#before will - # be called. On the other hand + # In the above case whenever you save an account the method Audit#before will + # be called. On the other hand # - # define_callbacks :save, :scope => [:kind, :name] + # define_callbacks :save, :scope => [:kind, :name] # - # would trigger Audit#before_save instead. That's constructed by calling - # "#{kind}_#{name}" on the given instance. In this case "kind" is "before" and - # "name" is "save". In this context ":kind" and ":name" have special meanings: ":kind" - # refers to the kind of callback (before/after/around) and ":name" refers to the - # method on which callbacks are being defined. + # would trigger Audit#before_save instead. That's constructed by calling + # #{kind}_#{name} on the given instance. In this case "kind" is "before" and + # "name" is "save". In this context +:kind+ and +:name+ have special meanings: +:kind+ + # refers to the kind of callback (before/after/around) and +:name+ refers to the + # method on which callbacks are being defined. # - # A declaration like + # A declaration like # - # define_callbacks :save, :scope => [:name] + # define_callbacks :save, :scope => [:name] # - # would call Audit#save. + # would call Audit#save. # def define_callbacks(*callbacks) config = callbacks.last.is_a?(Hash) ? callbacks.pop : {} From b461fe76f47dc34a6a958d1761ac0332421627fd Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Wed, 12 Jan 2011 22:37:34 -0500 Subject: [PATCH 14/26] editing comments regarding rescuable optoin in AS callbacks --- activesupport/lib/active_support/callbacks.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index f79363d953..6e284182b2 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -549,8 +549,9 @@ module ActiveSupport # halts the chain. # # * :rescuable - By default, after filters are not executed if - # the given block or a before filter raises an error. Set this option to - # true to change this behavior. + # the given block or a before filter raises an error. By setting this option + # to true exception raised by given block is stored and after + # executing all the after callbacks the stored exception is raised. # # * :scope - Indicates which methods should be executed when an object # is used as a callback. From 5f5e3b7e23f9c1534ba2a67e827a95c682ab0f3f Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Fri, 14 Jan 2011 02:34:59 -0600 Subject: [PATCH 15/26] Copy-edit and format Rails::Engine docs. --- railties/lib/rails/engine.rb | 176 ++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 84 deletions(-) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 1d81e08cd3..b945df5703 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -5,19 +5,20 @@ require 'rbconfig' require 'rails/engine/railties' module Rails - # Rails::Engine allows you to wrap a specific Rails application and share it accross - # different applications. Since Rails 3.0, every Rails::Application is nothing - # more than an Engine, allowing you to share it very easily. + # Rails::Engine allows you to wrap a specific Rails application and share it across + # different applications. Since Rails 3.0, every Rails::Application is nothing + # more than an Engine, allowing you to share it very easily. # - # Any Rails::Engine is also a Rails::Railtie, so the same methods (like rake_tasks and - # generators) and configuration available in the latter can also be used in the former. + # Any Rails::Engine is also a Rails::Railtie, so the same methods + # (like rake_tasks and generators) and configuration available in the + # latter can also be used in the former. # # == Creating an Engine # - # In Rails versions before to 3.0, your gems automatically behaved as Engine, however + # In Rails versions prior to 3.0, your gems automatically behaved as Engines, however, # this coupled Rails to Rubygems. Since Rails 3.0, if you want a gem to automatically - # behave as Engine, you have to specify an Engine for it somewhere inside your plugin - # lib folder (similar to how we specify a Railtie): + # behave as an Engine, you have to specify an Engine for it somewhere + # inside your plugin's lib folder (similar to how we specify a Railtie): # # # lib/my_engine.rb # module MyEngine @@ -25,16 +26,17 @@ module Rails # end # end # - # Then ensure that this file is loaded at the top of your config/application.rb (or in - # your Gemfile) and it will automatically load models, controllers and helpers - # inside app, load routes at "config/routes.rb", load locales at "config/locales/*", - # load tasks at "lib/tasks/*". + # Then ensure that this file is loaded at the top of your config/application.rb + # (or in your Gemfile) and it will automatically load models, controllers and helpers + # inside app, load routes at config/routes.rb, load locales at + # config/locales/*, and load tasks at lib/tasks/*. # # == Configuration # - # Besides the Railtie configuration which is shared across the application, in a - # Rails::Engine you can access autoload_paths, eager_load_paths and autoload_once_paths, - # which differently from a Railtie, are scoped to the current Engine. + # Besides the Railtie configuration which is shared across the application, in a + # Rails::Engine you can access autoload_paths, eager_load_paths + # and autoload_once_paths, which, differently from a Railtie, are scoped to + # the current Engine. # # Example: # @@ -49,7 +51,7 @@ module Rails # # == Generators # - # You can set up generators for engine with config.generators method: + # You can set up generators for Engines with config.generators method: # # class MyEngine < Rails::Engine # config.generators do |g| @@ -59,7 +61,7 @@ module Rails # end # end # - # You can also set generators for application by using config.app_generators: + # You can also set generators for application by using config.app_generators: # # class MyEngine < Rails::Engine # # note that you can also pass block to app_generators in the same way you @@ -70,18 +72,18 @@ module Rails # == Paths # # Since Rails 3.0, both your Application and Engines do not have hardcoded paths. - # This means that you are not required to place your controllers at "app/controllers", + # This means that you are not required to place your controllers at app/controllers, # but in any place which you find convenient. # - # For example, let's suppose you want to lay your controllers at lib/controllers, all - # you need to do is: + # For example, let's suppose you want to place your controllers in lib/controllers. + # All you would need to do is: # # class MyEngine < Rails::Engine # paths["app/controllers"] = "lib/controllers" # end # - # You can also have your controllers being loaded from both "app/controllers" and - # "lib/controllers": + # You can also have your controllers loaded from both app/controllers and + # lib/controllers: # # class MyEngine < Rails::Engine # paths["app/controllers"] << "lib/controllers" @@ -103,32 +105,33 @@ module Rails # paths["config/routes"] #=> ["config/routes.rb"] # end # - # Your Application class adds a couple more paths to this set. And as in your Application, - # all folders under "app" are automatically added to the load path. So if you have - # "app/observers", it's added by default. + # Your Application class adds a couple more paths to this set. And as in your + # Application,all folders under app are automatically added to the load path. + # So if you have app/observers, it's added by default. # # == Endpoint # - # Engine can be also a rack application. It can be useful if you have a rack application that + # An Engine can be also a rack application. It can be useful if you have a rack application that # you would like to wrap with Engine and provide some of the Engine's features. # - # To do that, use endpoint method: + # To do that, use the endpoint method: + # # module MyEngine # class Engine < Rails::Engine # endpoint MyRackApplication # end # end # - # Now you can mount your engine in application's routes just like that: + # Now you can mount your Engine in application's routes just like that: # - # MyRailsApp::Application.routes.draw do - # mount MyEngine::Engine => "/engine" - # end + # MyRailsApp::Application.routes.draw do + # mount MyEngine::Engine => "/engine" + # end # # == Middleware stack # - # As Engine can now be rack endpoint, it can also have a middleware stack. The usage is exactly - # the same as in application: + # As Engine can now be rack endpoint, it can also have a middleware stack. The usage is exactly + # the same as in Application: # # module MyEngine # class Engine < Rails::Engine @@ -148,30 +151,31 @@ module Rails # # == Mount priority # - # Note that now there can be more than one router in you application and it's better to avoid - # passing requests through many routers. Consider such situation: + # Note that now there can be more than one router in your application, and it's better to avoid + # passing requests through many routers. Consider this situation: # # MyRailsApp::Application.routes.draw do # mount MyEngine::Engine => "/blog" # match "/blog/omg" => "main#omg" # end # - # MyEngine is mounted at "/blog" path and additionaly "/blog/omg" points application's controller. - # In such situation request to "/blog/omg" will go through MyEngine and if there is no such route - # in Engine's routes, it will be dispatched to "main#omg". It's much better to swap that: + # MyEngine is mounted at /blog, and /blog/omg points to application's + # controller. In such a situation, requests to /blog/omg will go through MyEngine, + # and if there is no such route in Engine's routes, it will be dispatched to main#omg. + # It's much better to swap that: # # MyRailsApp::Application.routes.draw do # match "/blog/omg" => "main#omg" # mount MyEngine::Engine => "/blog" # end # - # Now, Engine will get only requests that were not handled by application. + # Now, Engine will get only requests that were not handled by Application. # # == Asset path # - # When you use engine with its own public directory, you will probably want to copy or symlink it - # to application's public directory. To simplify generating paths for assets, you can set asset_path - # for an Engine: + # When you use Engine with its own public directory, you will probably want to copy or symlink it + # to application's public directory. To simplify generating paths for assets, you can set asset_path + # for an Engine: # # module MyEngine # class Engine < Rails::Engine @@ -179,27 +183,30 @@ module Rails # end # end # - # With such config, asset paths will be automatically modified inside Engine: - # image_path("foo.jpg") #=> "/my_engine/images/foo.jpg" + # With such a config, asset paths will be automatically modified inside Engine: + # + # image_path("foo.jpg") #=> "/my_engine/images/foo.jpg" # # == Serving static files # - # By default, rails use ActionDispatch::Static to serve static files in development mode. This is ok + # By default, Rails uses ActionDispatch::Static to serve static files in development mode. This is ok # while you develop your application, but when you want to deploy it, assets from engine will not be # served by default. You should choose one of the two following strategies: # # * enable serving static files by setting config.serve_static_assets to true - # * copy engine's public files to application's public folder with rake ENGINE_NAME:install:assets, for example - # rake my_engine:install:assets + # * copy engine's public files to application's public folder with rake ENGINE_NAME:install:assets, for example + # rake my_engine:install:assets # # == Engine name # - # There are some places where engine's name is used: - # * routes: when you mount engine with mount(MyEngine::Engine => '/my_engine'), it's used as default :as option - # * some of the rake tasks are based on engine name, e.g. my_engine:install:migrations, my_engine:install:assets + # There are some places where an Engine's name is used: + # * routes: when you mount an Engine with mount(MyEngine::Engine => '/my_engine'), + # it's used as default :as option + # * some of the rake tasks are based on engine name, e.g. my_engine:install:migrations, + # my_engine:install:assets # - # Engine name is set by default based on class name. For MyEngine::Engine it will be my_engine_engine. - # You can change it manually it manually using engine_name method: + # Engine name is set by default based on class name. For MyEngine::Engine it will be + # my_engine_engine. You can change it manually it manually using the engine_name method: # # module MyEngine # class Engine < Rails::Engine @@ -209,12 +216,12 @@ module Rails # # == Isolated Engine # - # Normally when you create controllers, helpers and models inside engine, they are treated - # as they were created inside the application. This means all applications helpers and named routes - # will be available to your engine controllers. + # Normally when you create controllers, helpers and models inside an engine, they are treated + # as they were created inside the application. This means all application helpers and named routes + # will be available to your engine's controllers. # - # However, sometimes you want to isolate your engine from the application, specially if your engine - # have its own router. To do that, you simply need to call +isolate_namespace+. This method requires + # However, sometimes you want to isolate your engine from the application, especially if your engine + # has its own router. To do that, you simply need to call +isolate_namespace+. This method requires # you to pass a module where all your controllers, helpers and models should be nested to: # # module MyEngine @@ -223,7 +230,8 @@ module Rails # end # end # - # With such Engine, everything that is inside MyEngine module, will be isolated from application. + # With such an Engine, everything that is inside the +MyEngine+ module will be isolated from + # the application. # # Consider such controller: # @@ -232,24 +240,24 @@ module Rails # end # end # - # If engine is marked as isolated, FooController has access only to helpers from engine and - # url_helpers from MyEngine::Engine.routes. + # If engine is marked as isolated, +FooController+ has access only to helpers from engine and + # url_helpers from MyEngine::Engine.routes. # - # The next thing that changes in isolated engine is routes behaviour. Normally, when you namespace - # your controllers, you also need to do namespace all your routes. With isolated engine, + # The next thing that changes in isolated engines is the behaviour of routes. Normally, when you namespace + # your controllers, you also need to do namespace all your routes. With an isolated engine, # the namespace is applied by default, so you can ignore it in routes: # # MyEngine::Engine.routes.draw do # resources :articles # end - # - # The routes above will automatically point to MyEngine::ApplicationContoller. Further more, you don't - # need to use longer url helpers like "my_engine_articles_path". Instead, you shuold simply use - # articles_path as you would do with your application. # - # To make that behaviour consistent with other parts of framework, isolated engine has influence also on - # ActiveModel::Naming. When you use namespaced model, like MyEngine::Article, it will normally - # use the prefix "my_engine". In isolated engine, the prefix will be ommited in url helpers and + # The routes above will automatically point to MyEngine::ApplicationContoller. Furthermore, you don't + # need to use longer url helpers like my_engine_articles_path. Instead, you shuold simply use + # articles_path as you would do with your application. + # + # To make that behaviour consistent with other parts of the framework, an isolated engine also has influence on + # ActiveModel::Naming. When you use a namespaced model, like MyEngine::Article, it will normally + # use the prefix "my_engine". In an isolated engine, the prefix will be ommited in url helpers and # form fields for convenience. # # polymorphic_url(MyEngine::Article.new) #=> "articles_path" @@ -264,9 +272,9 @@ module Rails # # == Using Engine's routes outside Engine # - # Since now you can mount engine inside application's routes, you do not have direct access to engine's - # url_helpers inside application. When you mount Engine in application's routes, a special helper is - # created to allow you to do that. Consider such scenario: + # Since you can now mount engine inside application's routes, you do not have direct access to engine's + # url_helpers inside application. When you mount Engine in application's routes, a special helper is + # created to allow you to do that. Consider such a scenario: # # # APP/config/routes.rb # MyApplication::Application.routes.draw do @@ -274,7 +282,7 @@ module Rails # match "/foo" => "foo#index" # end # - # Now, you can use my_engine helper inside your application: + # Now, you can use the my_engine helper inside your application: # # class FooController < ApplicationController # def index @@ -282,7 +290,7 @@ module Rails # end # end # - # There is also 'main_app' helper that gives you access to application's routes inside Engine: + # There is also a main_app helper that gives you access to application's routes inside Engine: # # module MyEngine # class BarController @@ -292,34 +300,34 @@ module Rails # end # end # - # Note that the :as option given to mount takes the engine_name as default, so most of the time - # you can simply ommit it. + # Note that the :as option given to mount takes the engine_name as default, so most of the time + # you can simply omit it. # - # Finally, if you want to generate url to engine's route using polymorphic_url, you also need + # Finally, if you want to generate a url to engine's route using polymorphic_url, you also need # to pass the engine helper. Let's say that you want to create a form pointing to one of the # engine's routes. All you need to do is pass the helper as the first element in array with # attributes for url: # - # form_for([my_engine, @user]) + # form_for([my_engine, @user]) # - # This code will use my_engine.user_path(@user) to generate the proper route. + # This code will use my_engine.user_path(@user) to generate the proper route. # # == Migrations & seed data # - # Engines can have their own migrations. Default path for migrations is exactly the same - # as in application: db/migrate + # Engines can have their own migrations. The default path for migrations is exactly the same + # as in application: db/migrate # # To use engine's migrations in application you can use rake task, which copies them to # application's dir: # # rake ENGINE_NAME:install:migrations # - # Note that some of the migrations may be skipped if migration with the same name already exists - # in application. In such situation you must decide whether to leave that migration or rename the + # Note that some of the migrations may be skipped if a migration with the same name already exists + # in application. In such a situation you must decide whether to leave that migration or rename the # migration in application and rerun copying migrations. # # If your engine has migrations, you may also want to prepare data for the database in - # seeds.rb file. You can load that data using load_seed method, e.g. + # the seeds.rb file. You can load that data using the load_seed method, e.g. # # MyEngine::Engine.load_seed # From 31767b003227148ce06b7c8df0f533b7cdeddd9b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 14 Jan 2011 22:10:22 +0530 Subject: [PATCH 16/26] ends_width => ends_with --- railties/guides/source/active_support_core_extensions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 9a1f913ded..c283a9bd99 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1264,7 +1264,7 @@ Active Support adds that functionality to % in previous versions of Rub NOTE: Defined in +active_support/core_ext/string/interpolation.rb+. -h4. +starts_with?+ and +ends_width?+ +h4. +starts_with?+ and +ends_with?+ Active Support defines 3rd person aliases of +String#start_with?+ and +String#end_with?+: From 93c208a630e5cd96071ed5581fcd1c23708b3817 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 14 Jan 2011 22:51:15 +0530 Subject: [PATCH 17/26] use new AR api --- railties/guides/source/active_record_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile index f0081b48c0..b7926f3a3b 100644 --- a/railties/guides/source/active_record_basics.textile +++ b/railties/guides/source/active_record_basics.textile @@ -180,7 +180,7 @@ Active Record provides a rich API for accessing data within a database. Below ar # find all users named David who are Code Artists and sort by created_at in reverse chronological order - users = User.all(:conditions => { :name => 'David', :occupation => 'Code Artist'}, :order => 'created_at DESC') + users = User.where(:name => 'David', :occupation => 'Code Artist').order('created_at DESC') You can learn more about querying an Active Record model in the "Active Record Query Interface":"active_record_querying.html" guide. From da82b0a746c36ea1274041b0d2401903abf33904 Mon Sep 17 00:00:00 2001 From: brainopia Date: Sat, 15 Jan 2011 03:10:10 +0300 Subject: [PATCH 18/26] Remove reference to ActiveRecord from ActiveModel comments --- activemodel/lib/active_model/observing.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index 0d2dd36e59..bf4fd0740c 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -13,14 +13,18 @@ module ActiveModel # # Activates the observers assigned. Examples: # + # class ORM + # include ActiveModel::Observing + # end + # # # Calls PersonObserver.instance - # ActiveRecord::Base.observers = :person_observer + # ORM.observers = :person_observer # # # Calls Cacher.instance and GarbageCollector.instance - # ActiveRecord::Base.observers = :cacher, :garbage_collector + # ORM.observers = :cacher, :garbage_collector # # # Same as above, just using explicit class references - # ActiveRecord::Base.observers = Cacher, GarbageCollector + # ORM.observers = Cacher, GarbageCollector # # Note: Setting this does not instantiate the observers yet. # +instantiate_observers+ is called during startup, and before From b31ef7ee83f3fe808f7534172ce2bf22ef6c7cc0 Mon Sep 17 00:00:00 2001 From: Jordi Romero Date: Sat, 15 Jan 2011 01:15:05 +0100 Subject: [PATCH 19/26] document ActiveRecord's except and only Document methods that allow easily override arel queries --- .../lib/active_record/relation/spawn_methods.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index 5acf3ec83a..ae777208db 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -61,6 +61,13 @@ module ActiveRecord alias :& :merge + # Removes from the query the condition(s) specified in +skips+. + # + # Example: + # + # Post.order('id asc').except(:order) # discards the order condition + # Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order + # def except(*skips) result = self.class.new(@klass, table) @@ -75,6 +82,13 @@ module ActiveRecord result end + # Removes any condition from the query other than the one(s) specified in +onlies+. + # + # Example: + # + # Post.order('id asc').only(:where) # discards the order condition + # Post.order('id asc').only(:where, :order) # uses the specified order + # def only(*onlies) result = self.class.new(@klass, table) From 1a051259b426d624e846f76c3fc6011693603e55 Mon Sep 17 00:00:00 2001 From: Daniel Schierbeck Date: Sat, 15 Jan 2011 17:54:02 +0100 Subject: [PATCH 20/26] Properly indent code example block --- .../active_model/mass_assignment_security.rb | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/activemodel/lib/active_model/mass_assignment_security.rb b/activemodel/lib/active_model/mass_assignment_security.rb index 66cd9fdde6..97e31d4243 100644 --- a/activemodel/lib/active_model/mass_assignment_security.rb +++ b/activemodel/lib/active_model/mass_assignment_security.rb @@ -20,33 +20,33 @@ module ActiveModel # For example, a logged in user may need to assign additional attributes depending # on their role: # - # class AccountsController < ApplicationController - # include ActiveModel::MassAssignmentSecurity + # class AccountsController < ApplicationController + # include ActiveModel::MassAssignmentSecurity # - # attr_accessible :first_name, :last_name + # attr_accessible :first_name, :last_name + # + # def self.admin_accessible_attributes + # accessible_attributes + [ :plan_id ] + # end + # + # def update + # ... + # @account.update_attributes(account_params) + # ... + # end + # + # protected + # + # def account_params + # sanitize_for_mass_assignment(params[:account]) + # end + # + # def mass_assignment_authorizer + # admin ? admin_accessible_attributes : super + # end # - # def self.admin_accessible_attributes - # accessible_attributes + [ :plan_id ] # end # - # def update - # ... - # @account.update_attributes(account_params) - # ... - # end - # - # protected - # - # def account_params - # sanitize_for_mass_assignment(params[:account]) - # end - # - # def mass_assignment_authorizer - # admin ? admin_accessible_attributes : super - # end - # - # end - # module ClassMethods # Attributes named in this macro are protected from mass-assignment # whenever attributes are sanitized before assignment. From 100ab5bd431e1cf9f4fdf08c8724918f482c4684 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 15 Jan 2011 23:39:32 +0530 Subject: [PATCH 21/26] Documented the except and only conditions in the guides. Took the cue from Jordi Ramero's commit (b31ef7ee83f3fe808f7534172ce2bf22ef6c7cc0) --- .../source/active_record_querying.textile | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 22358029d4..64a68f7592 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -19,8 +19,6 @@ Code examples throughout this guide will refer to one or more of the following m TIP: All of the following models use +id+ as the primary key, unless specified otherwise. -
- class Client < ActiveRecord::Base has_one :address @@ -461,6 +459,36 @@ SELECT * FROM orders GROUP BY date(created_at) HAVING created_at > '2009-01-15' This will return single order objects for each day, but only for the last month. +h3. Overriding Conditions + +You can specify certain conditions to be excepted by using the +except+ method. + +For example: + + +Post.where('id > 10').limit(20).order('id asc').except(:order) + + +The SQL that would be executed: + + +SELECT * FROM posts WHERE id > 10 LIMIT 20 + + +You can also override conditions using the +only+ method. + +For example: + + +Post.where('id > 10').limit(20).order('id desc').only(:order, :where) + + +The SQL that would be executed: + + +SELECT * FROM posts WHERE id > 10 ORDER BY id DESC + + h3. Readonly Objects Active Record provides +readonly+ method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception. From 3c6c2404319931bb27256f190d1f9950149e9a53 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 15 Jan 2011 23:47:41 +0530 Subject: [PATCH 22/26] Document the LANGUAGE option for generating guides --- .../guides/source/ruby_on_rails_guides_guidelines.textile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile index a2e830b574..07f86edfb7 100644 --- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile +++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile @@ -62,7 +62,13 @@ To force process of all the guides, pass +ALL=1+. It is also recommended that you work with +WARNINGS=1+, this detects duplicate IDs and warns about broken internal links. -h3. HTML validation +If you want to generate guides in languages other than English, you can keep them in a separate directory under +source+ (eg. source/es) and use the +LANGUAGE+ environment variable. + + +rake generate_guides LANGUAGE=es + + +h3. HTML Validation Please do validate the generated HTML with From 77e1a99970c8bd454beaae502d4379309402afa5 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 17 Jan 2011 00:16:00 +0530 Subject: [PATCH 23/26] minor edits --- railties/guides/source/testing.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 733c8a755e..5f0889f406 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -229,13 +229,13 @@ $ rake db:test:load Above +rake db:migrate+ runs any pending migrations on the _development_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current +db/schema.rb+. On subsequent attempts, it is a good idea to first run +db:test:prepare+, as it first checks for pending migrations and warns you appropriately. -NOTE: +db:test:prepare+ will fail with an error if +db/schema.rb+ doesn't exists. +NOTE: +db:test:prepare+ will fail with an error if +db/schema.rb+ doesn't exist. h5. Rake Tasks for Preparing your Application for Testing |_.Tasks |_.Description| |+rake db:test:clone+ |Recreate the test database from the current environment's database schema| -|+rake db:test:clone_structure+ |Recreate the test databases from the development structure| +|+rake db:test:clone_structure+ |Recreate the test database from the development structure| |+rake db:test:load+ |Recreate the test database from the current +schema.rb+| |+rake db:test:prepare+ |Check for pending migrations and load the test schema| |+rake db:test:purge+ |Empty the test database.| @@ -512,12 +512,12 @@ After a request has been made by using one of the 5 methods (+get+, +post+, etc. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for +assigns+. For example: - flash["gordon"] flash[:gordon] - session["shmession"] session[:shmession] - cookies["are_good_for_u"] cookies[:are_good_for_u] +flash["gordon"] flash[:gordon] +session["shmession"] session[:shmession] +cookies["are_good_for_u"] cookies[:are_good_for_u] # Because you can't use assigns[:something] for historical reasons: - assigns["something"] assigns(:something) +assigns["something"] assigns(:something) h4. Instance Variables Available From 4b7dad2df3fc252acdb3fd8362370daac16540e4 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Tue, 18 Jan 2011 00:35:07 +0100 Subject: [PATCH 24/26] ActiveRecord#save(false) is now deprecated, now it is save(:validate => false) --- activerecord/lib/active_record/validations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index f367315b22..26c1a9db93 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -37,7 +37,7 @@ module ActiveRecord end end - # The validation process on save can be skipped by passing false. The regular Base#save method is + # The validation process on save can be skipped by passing :validate => false. The regular Base#save method is # replaced with this when the validations module is mixed in, which it is by default. def save(options={}) perform_validations(options) ? super : false From 2373eedc88661a11c1ac58d8e98a9cb5b6c7dba1 Mon Sep 17 00:00:00 2001 From: Matt Buck Date: Wed, 19 Jan 2011 14:30:28 -0600 Subject: [PATCH 25/26] Make all references to engines lowercase in docs. --- railties/lib/rails/engine.rb | 72 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b945df5703..6e5e842370 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -7,18 +7,18 @@ require 'rails/engine/railties' module Rails # Rails::Engine allows you to wrap a specific Rails application and share it across # different applications. Since Rails 3.0, every Rails::Application is nothing - # more than an Engine, allowing you to share it very easily. + # more than an engine, allowing you to share it very easily. # # Any Rails::Engine is also a Rails::Railtie, so the same methods - # (like rake_tasks and generators) and configuration available in the + # (like rake_tasks and +generators+) and configuration available in the # latter can also be used in the former. # # == Creating an Engine # - # In Rails versions prior to 3.0, your gems automatically behaved as Engines, however, + # In Rails versions prior to 3.0, your gems automatically behaved as engines, however, # this coupled Rails to Rubygems. Since Rails 3.0, if you want a gem to automatically - # behave as an Engine, you have to specify an Engine for it somewhere - # inside your plugin's lib folder (similar to how we specify a Railtie): + # behave as an engine, you have to specify an +Engine+ for it somewhere inside + # your plugin's +lib+ folder (similar to how we specify a +Railtie+): # # # lib/my_engine.rb # module MyEngine @@ -27,16 +27,16 @@ module Rails # end # # Then ensure that this file is loaded at the top of your config/application.rb - # (or in your Gemfile) and it will automatically load models, controllers and helpers - # inside app, load routes at config/routes.rb, load locales at + # (or in your +Gemfile+) and it will automatically load models, controllers and helpers + # inside +app+, load routes at config/routes.rb, load locales at # config/locales/*, and load tasks at lib/tasks/*. # # == Configuration # - # Besides the Railtie configuration which is shared across the application, in a + # Besides the +Railtie+ configuration which is shared across the application, in a # Rails::Engine you can access autoload_paths, eager_load_paths # and autoload_once_paths, which, differently from a Railtie, are scoped to - # the current Engine. + # the current engine. # # Example: # @@ -51,7 +51,7 @@ module Rails # # == Generators # - # You can set up generators for Engines with config.generators method: + # You can set up generators for engines with config.generators method: # # class MyEngine < Rails::Engine # config.generators do |g| @@ -61,7 +61,7 @@ module Rails # end # end # - # You can also set generators for application by using config.app_generators: + # You can also set generators for an application by using config.app_generators: # # class MyEngine < Rails::Engine # # note that you can also pass block to app_generators in the same way you @@ -71,11 +71,11 @@ module Rails # # == Paths # - # Since Rails 3.0, both your Application and Engines do not have hardcoded paths. + # Since Rails 3.0, both your application and engines do not have hardcoded paths. # This means that you are not required to place your controllers at app/controllers, # but in any place which you find convenient. # - # For example, let's suppose you want to place your controllers in lib/controllers. + # For example, let's suppose you want to place your controllers in lib/controllers. # All you would need to do is: # # class MyEngine < Rails::Engine @@ -89,7 +89,7 @@ module Rails # paths["app/controllers"] << "lib/controllers" # end # - # The available paths in an Engine are: + # The available paths in an engine are: # # class MyEngine < Rails::Engine # paths["app"] #=> ["app"] @@ -105,16 +105,16 @@ module Rails # paths["config/routes"] #=> ["config/routes.rb"] # end # - # Your Application class adds a couple more paths to this set. And as in your - # Application,all folders under app are automatically added to the load path. + # Your Application class adds a couple more paths to this set. And as in your + # Application,all folders under +app+ are automatically added to the load path. # So if you have app/observers, it's added by default. # # == Endpoint # - # An Engine can be also a rack application. It can be useful if you have a rack application that - # you would like to wrap with Engine and provide some of the Engine's features. + # An engine can be also a rack application. It can be useful if you have a rack application that + # you would like to wrap with +Engine+ and provide some of the +Engine+'s features. # - # To do that, use the endpoint method: + # To do that, use the +endpoint+ method: # # module MyEngine # class Engine < Rails::Engine @@ -122,7 +122,7 @@ module Rails # end # end # - # Now you can mount your Engine in application's routes just like that: + # Now you can mount your engine in application's routes just like that: # # MyRailsApp::Application.routes.draw do # mount MyEngine::Engine => "/engine" @@ -130,7 +130,7 @@ module Rails # # == Middleware stack # - # As Engine can now be rack endpoint, it can also have a middleware stack. The usage is exactly + # As an engine can now be rack endpoint, it can also have a middleware stack. The usage is exactly # the same as in Application: # # module MyEngine @@ -141,8 +141,8 @@ module Rails # # == Routes # - # If you don't specify endpoint, routes will be used as default endpoint. You can use them - # just like you use application's routes: + # If you don't specify an endpoint, routes will be used as the default endpoint. You can use them + # just like you use an application's routes: # # # ENGINE/config/routes.rb # MyEngine::Engine.routes.draw do @@ -159,9 +159,9 @@ module Rails # match "/blog/omg" => "main#omg" # end # - # MyEngine is mounted at /blog, and /blog/omg points to application's - # controller. In such a situation, requests to /blog/omg will go through MyEngine, - # and if there is no such route in Engine's routes, it will be dispatched to main#omg. + # +MyEngine+ is mounted at /blog, and /blog/omg points to application's + # controller. In such a situation, requests to /blog/omg will go through +MyEngine+, + # and if there is no such route in +Engine+'s routes, it will be dispatched to main#omg. # It's much better to swap that: # # MyRailsApp::Application.routes.draw do @@ -169,13 +169,13 @@ module Rails # mount MyEngine::Engine => "/blog" # end # - # Now, Engine will get only requests that were not handled by Application. + # Now, +Engine+ will get only requests that were not handled by +Application+. # # == Asset path # - # When you use Engine with its own public directory, you will probably want to copy or symlink it + # When you use +Engine+ with its own public directory, you will probably want to copy or symlink it # to application's public directory. To simplify generating paths for assets, you can set asset_path - # for an Engine: + # for an engine: # # module MyEngine # class Engine < Rails::Engine @@ -183,14 +183,14 @@ module Rails # end # end # - # With such a config, asset paths will be automatically modified inside Engine: + # With such a config, asset paths will be automatically modified inside +Engine+: # # image_path("foo.jpg") #=> "/my_engine/images/foo.jpg" # # == Serving static files # # By default, Rails uses ActionDispatch::Static to serve static files in development mode. This is ok - # while you develop your application, but when you want to deploy it, assets from engine will not be + # while you develop your application, but when you want to deploy it, assets from an engine will not be # served by default. You should choose one of the two following strategies: # # * enable serving static files by setting config.serve_static_assets to true @@ -230,7 +230,7 @@ module Rails # end # end # - # With such an Engine, everything that is inside the +MyEngine+ module will be isolated from + # With such an engine, everything that is inside the +MyEngine+ module will be isolated from # the application. # # Consider such controller: @@ -240,7 +240,7 @@ module Rails # end # end # - # If engine is marked as isolated, +FooController+ has access only to helpers from engine and + # If an engine is marked as isolated, +FooController+ has access only to helpers from +Engine+ and # url_helpers from MyEngine::Engine.routes. # # The next thing that changes in isolated engines is the behaviour of routes. Normally, when you namespace @@ -272,8 +272,8 @@ module Rails # # == Using Engine's routes outside Engine # - # Since you can now mount engine inside application's routes, you do not have direct access to engine's - # url_helpers inside application. When you mount Engine in application's routes, a special helper is + # Since you can now mount an engine inside application's routes, you do not have direct access to +Engine+'s + # url_helpers inside +Application+. When you mount an engine in an application's routes, a special helper is # created to allow you to do that. Consider such a scenario: # # # APP/config/routes.rb @@ -303,7 +303,7 @@ module Rails # Note that the :as option given to mount takes the engine_name as default, so most of the time # you can simply omit it. # - # Finally, if you want to generate a url to engine's route using polymorphic_url, you also need + # Finally, if you want to generate a url to an engine's route using polymorphic_url, you also need # to pass the engine helper. Let's say that you want to create a form pointing to one of the # engine's routes. All you need to do is pass the helper as the first element in array with # attributes for url: From 94e0f1db1cf17aa86fed5d7dad50f9e82238900a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20B=C3=BChlmann?= Date: Wed, 19 Jan 2011 22:03:54 +0100 Subject: [PATCH 26/26] use name instead of title in example --- railties/guides/source/i18n.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index bb8bf8b240..e47ac7aed6 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -713,12 +713,12 @@ end Then Active Record will look for messages in this order: -activerecord.errors.models.admin.attributes.title.blank +activerecord.errors.models.admin.attributes.name.blank activerecord.errors.models.admin.blank -activerecord.errors.models.user.attributes.title.blank +activerecord.errors.models.user.attributes.name.blank activerecord.errors.models.user.blank activerecord.errors.messages.blank -errors.attributes.title.blank +errors.attributes.name.blank errors.messages.blank