From 3d449dee5ed60b4d6c688c919c527dd70f528043 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Fri, 8 Nov 2013 15:07:38 +0530 Subject: Update commands.rb content in initialization guide [ci skip] --- guides/source/initialization.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.md b/guides/source/initialization.md index 33eb74dcd9..29c7294145 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -126,7 +126,7 @@ A standard Rails application depends on several gems, specifically: ### `rails/commands.rb` -Once `config/boot.rb` has finished, the next file that is required is `rails/commands` which will execute a command based on the arguments passed in. In this case, the `ARGV` array simply contains `server` which is extracted into the `command` variable using these lines: +Once `config/boot.rb` has finished, the next file that is required is `rails/commands`, which helps in expanding aliases. In the current case, the `ARGV` array simply contains `server` which will be passed over to `rails/commands_tasks`. ```ruby ARGV << '--help' if ARGV.empty? @@ -142,12 +142,18 @@ aliases = { command = ARGV.shift command = aliases[command] || command + +require 'rails/commands/commands_tasks' + +Rails::CommandsTasks.new(ARGV).run_command!(command) ``` TIP: As you can see, an empty ARGV list will make Rails show the help snippet. -If we used `s` rather than `server`, Rails will use the `aliases` defined in the file and match them to their respective commands. With the `server` command, Rails will run this code: +If we had used `s` rather than `server`, Rails would have used the `aliases` defined here to find the matching command. + +With the `server` command, Rails will run this code: ```ruby when 'server' -- cgit v1.2.3 From 83271a64f961e8138bf1e125251860333ba88f72 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Fri, 8 Nov 2013 15:13:59 +0530 Subject: Add section for command_tasks in initialization guide [ci skip] --- guides/source/initialization.md | 54 ++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 12 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.md b/guides/source/initialization.md index 29c7294145..0cd0492cab 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -126,7 +126,10 @@ A standard Rails application depends on several gems, specifically: ### `rails/commands.rb` -Once `config/boot.rb` has finished, the next file that is required is `rails/commands`, which helps in expanding aliases. In the current case, the `ARGV` array simply contains `server` which will be passed over to `rails/commands_tasks`. +Once `config/boot.rb` has finished, the next file that is required is +`rails/commands`, which helps in expanding aliases. In the current case, the +`ARGV` array simply contains `server` which will be passed over to +`rails/commands_tasks`. ```ruby ARGV << '--help' if ARGV.empty? @@ -151,28 +154,55 @@ Rails::CommandsTasks.new(ARGV).run_command!(command) TIP: As you can see, an empty ARGV list will make Rails show the help snippet. -If we had used `s` rather than `server`, Rails would have used the `aliases` defined here to find the matching command. +If we had used `s` rather than `server`, Rails would have used the `aliases` +defined here to find the matching command. -With the `server` command, Rails will run this code: +### `rails/commands/command_tasks.rb` + +When one types an incorrect rails command, the `run_command` is responsible for +throwing an error message. If the command is valid, a function of the same name +is called. + +```ruby +COMMAND_WHITELIST = %(plugin generate destroy console server dbconsole application runner new version help) + +def run_command!(command) + if COMMAND_WHITELIST.include?(command) + send(command) + else + write_error_message(command) + end +end +``` + +With the `server` command, Rails will further run the following code: ```ruby -when 'server' - # Change to the application's path if there is no config.ru file in current directory. - # This allows us to run `rails server` from other directories, but still get - # the main config.ru and properly set the tmp directory. - Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru")) +def set_application_directory! + Dir.chdir(File.expand_path('../../', APP_PATH)) unless + File.exist?(File.expand_path("config.ru")) +end + +def server + set_application_directory! + require_command!("server") - require 'rails/commands/server' Rails::Server.new.tap do |server| - # We need to require application after the server sets environment, - # otherwise the --environment option given to the server won't propagate. require APP_PATH Dir.chdir(Rails.application.root) server.start end +end + +def require_command!(command) + require "rails/commands/#{command}" +end ``` -This file will change into the Rails root directory (a path two directories up from `APP_PATH` which points at `config/application.rb`), but only if the `config.ru` file isn't found. This then requires `rails/commands/server` which sets up the `Rails::Server` class. +This file will change into the Rails root directory (a path two directories up +from `APP_PATH` which points at `config/application.rb`), but only if the +`config.ru` file isn't found. This then requires `rails/commands/server` which +sets up the `Rails::Server` class. ```ruby require 'fileutils' -- cgit v1.2.3 From 5735a77def338125738c6de9c72961bb4df49513 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 12 Nov 2013 19:14:10 +0530 Subject: Fix RailsServer#start content in initialization guide [ci skip] --- guides/source/initialization.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.md b/guides/source/initialization.md index 0cd0492cab..f1bbb5bb13 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -330,37 +330,43 @@ and it's free for you to change based on your needs. ### `Rails::Server#start` -After `config/application` is loaded, `server.start` is called. This method is defined like this: +After `config/application` is loaded, `server.start` is called. This method is +defined like this: ```ruby def start - url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}" - puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}" - puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}" - puts "=> Run `rails server -h` for more startup options" + print_boot_information trap(:INT) { exit } - puts "=> Ctrl-C to shutdown server" unless options[:daemonize] + create_tmp_directories + log_to_stdout if options[:log_stdout] - #Create required tmp directories if not found - %w(cache pids sessions sockets).each do |dir_to_make| - FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make)) + super + ... +end + +private + + def print_boot_information + ... + puts "=> Run `rails server -h` for more startup options" + puts "=> Ctrl-C to shutdown server" unless options[:daemonize] end - unless options[:daemonize] + def create_tmp_directories + %w(cache pids sessions sockets).each do |dir_to_make| + FileUtils.mkdir_p(File.join(Rails.root, 'tmp', dir_to_make)) + end + end + + def log_to_stdout wrapped_app # touch the app so the logger is set up console = ActiveSupport::Logger.new($stdout) console.formatter = Rails.logger.formatter + console.level = Rails.logger.level Rails.logger.extend(ActiveSupport::Logger.broadcast(console)) end - - super -ensure - # The '-h' option calls exit before @options is set. - # If we call 'options' with it unset, we get double help banners. - puts 'Exiting' unless @options && options[:daemonize] -end ``` This is where the first output of the Rails initialization happens. This -- cgit v1.2.3 From b9a4560d91d382600164e69cf98d8eb6688447df Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Tue, 12 Nov 2013 19:23:42 +0530 Subject: [ci skip] Replace #=> with # => --- guides/source/2_2_release_notes.md | 2 +- guides/source/active_record_validations.md | 18 +++++++++--------- guides/source/active_support_core_extensions.md | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'guides/source') diff --git a/guides/source/2_2_release_notes.md b/guides/source/2_2_release_notes.md index 7db4cf07e7..c11d1240c4 100644 --- a/guides/source/2_2_release_notes.md +++ b/guides/source/2_2_release_notes.md @@ -327,7 +327,7 @@ Other features of memoization include `unmemoize`, `unmemoize_all`, and `memoize The `each_with_object` method provides an alternative to `inject`, using a method backported from Ruby 1.9. It iterates over a collection, passing the current element and the memo into the block. ```ruby -%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } #=> {'foo' => 'FOO', 'bar' => 'BAR'} +%w(foo bar).each_with_object({}) { |str, hsh| hsh[str] = str.upcase } # => {'foo' => 'FOO', 'bar' => 'BAR'} ``` Lead Contributor: [Adam Keys](http://therealadam.com/) diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 0df52a655f..cbd1ac9bdf 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -175,28 +175,28 @@ class Person < ActiveRecord::Base end >> p = Person.new -#=> # +# => # >> p.errors.messages -#=> {} +# => {} >> p.valid? -#=> false +# => false >> p.errors.messages -#=> {name:["can't be blank"]} +# => {name:["can't be blank"]} >> p = Person.create -#=> # +# => # >> p.errors.messages -#=> {name:["can't be blank"]} +# => {name:["can't be blank"]} >> p.save -#=> false +# => false >> p.save! -#=> ActiveRecord::RecordInvalid: Validation failed: Name can't be blank +# => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank >> Person.create! -#=> ActiveRecord::RecordInvalid: Validation failed: Name can't be blank +# => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank ``` `invalid?` is simply the inverse of `valid?`. It triggers your validations, diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index b72ebd63ee..69185177b5 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -176,14 +176,14 @@ duplicate = array.dup duplicate.push 'another-string' # the object was duplicated, so the element was added only to the duplicate -array #=> ['string'] -duplicate #=> ['string', 'another-string'] +array # => ['string'] +duplicate # => ['string', 'another-string'] duplicate.first.gsub!('string', 'foo') # first element was not duplicated, it will be changed in both arrays -array #=> ['foo'] -duplicate #=> ['foo', 'another-string'] +array # => ['foo'] +duplicate # => ['foo', 'another-string'] ``` As you can see, after duplicating the `Array` instance, we got another object, therefore we can modify it and the original object will stay unchanged. This is not true for array's elements, however. Since `dup` does not make deep copy, the string inside the array is still the same object. @@ -196,8 +196,8 @@ duplicate = array.deep_dup duplicate.first.gsub!('string', 'foo') -array #=> ['string'] -duplicate #=> ['foo'] +array # => ['string'] +duplicate # => ['foo'] ``` If the object is not duplicable, `deep_dup` will just return it: @@ -1542,7 +1542,7 @@ ActiveSupport::Inflector.inflections do |inflect| inflect.acronym 'SSL' end -"SSLError".underscore.camelize #=> "SSLError" +"SSLError".underscore.camelize # => "SSLError" ``` `camelize` is aliased to `camelcase`. -- cgit v1.2.3 From 006f710361f86c81bbcbb04e12aae78d04651622 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Wed, 13 Nov 2013 13:23:09 +0530 Subject: Correct guide relating MiddlewareStackProxy with Enumerable [ci skip] Enumerable.instance_methods & Rails::Configuration::MiddlewareStackProxy.instance_methods # => [:as_json] MiddlewareStackProxy does not share any notable methods with Enumerable. --- guides/source/rails_on_rack.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md index 7ef54a45bc..acab7a151c 100644 --- a/guides/source/rails_on_rack.md +++ b/guides/source/rails_on_rack.md @@ -182,18 +182,17 @@ You can swap an existing middleware in the middleware stack using `config.middle config.middleware.swap ActionDispatch::ShowExceptions, Lifo::ShowExceptions ``` -#### Middleware Stack is an Enumerable +#### Deleting a Middleware -The middleware stack behaves just like a normal `Enumerable`. You can use any `Enumerable` methods to manipulate or interrogate the stack. The middleware stack also implements some `Array` methods including `[]`, `unshift` and `delete`. Methods described in the section above are just convenience methods. - -Append following lines to your application configuration: +Add the following lines to your application configuration: ```ruby # config/application.rb config.middleware.delete "Rack::Lock" ``` -And now if you inspect the middleware stack, you'll find that `Rack::Lock` will not be part of it. +And now if you inspect the middleware stack, you'll find that `Rack::Lock` is +not a part of it. ```bash $ rake middleware -- cgit v1.2.3 From ea5d3544d2bd47ee40301c4c280935c321e7c5a8 Mon Sep 17 00:00:00 2001 From: Alex Johnson Date: Wed, 13 Nov 2013 13:33:53 +0530 Subject: Remove outdated guide on using rack builder w/o rails middleware [ci skip] --- guides/source/rails_on_rack.md | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md index acab7a151c..b42c8fb81b 100644 --- a/guides/source/rails_on_rack.md +++ b/guides/source/rails_on_rack.md @@ -318,26 +318,6 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol TIP: It's possible to use any of the above middlewares in your custom Rack stack. -### Using Rack Builder - -The following shows how to replace use `Rack::Builder` instead of the Rails supplied `MiddlewareStack`. - -Clear the existing Rails middleware stack - -```ruby -# config/application.rb -config.middleware.clear -``` - -
-Add a `config.ru` file to `Rails.root` - -```ruby -# config.ru -use MyOwnStackFromScratch -run Rails.application -``` - Resources --------- -- cgit v1.2.3 From deeeaef6d2f49edb4eda0cfbab7f585a3eb520be Mon Sep 17 00:00:00 2001 From: Harshad Sabne Date: Wed, 13 Nov 2013 20:48:40 +0530 Subject: Fix broken Wikipedia link. --- guides/source/i18n.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/i18n.md b/guides/source/i18n.md index 6b36f67874..e34484a324 100644 --- a/guides/source/i18n.md +++ b/guides/source/i18n.md @@ -1035,7 +1035,7 @@ If you found this guide useful, please consider recommending its authors on [wor Footnotes --------- -[^1]: Or, to quote [Wikipedia](http://en.wikipedia.org/wiki/Internationalization_and_localization:) _"Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."_ +[^1]: Or, to quote [Wikipedia](http://en.wikipedia.org/wiki/Internationalization_and_localization): _"Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting software for a specific region or language by adding locale-specific components and translating text."_ [^2]: Other backends might allow or require to use other formats, e.g. a GetText backend might allow to read GetText files. -- cgit v1.2.3 From 4a98938ff4de038e003ec091e5e663876e4f3817 Mon Sep 17 00:00:00 2001 From: Harshad Sabne Date: Fri, 15 Nov 2013 22:32:44 +0530 Subject: Update action_controller_overview.md [ci skip] Code style adherence --- guides/source/action_controller_overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index cd4a1a0792..5bea8ff3a3 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -350,7 +350,7 @@ For most stores, this ID is used to look up the session data on the server, e.g. The CookieStore can store around 4kB of data - much less than the others - but this is usually enough. Storing large amounts of data in the session is discouraged no matter which session store your application uses. You should especially avoid storing complex objects (anything other than basic Ruby objects, the most common example being model instances) in the session, as the server might not be able to reassemble them between requests, which will result in an error. -If your user sessions don't store critical data or don't need to be around for long periods (for instance if you just use the flash for messaging), you can consider using ActionDispatch::Session::CacheStore. This will store sessions using the cache implementation you have configured for your application. The advantage of this is that you can use your existing cache infrastructure for storing sessions without requiring any additional setup or administration. The downside, of course, is that the sessions will be ephemeral and could disappear at any time. +If your user sessions don't store critical data or don't need to be around for long periods (for instance if you just use the flash for messaging), you can consider using `ActionDispatch::Session::CacheStore`. This will store sessions using the cache implementation you have configured for your application. The advantage of this is that you can use your existing cache infrastructure for storing sessions without requiring any additional setup or administration. The downside, of course, is that the sessions will be ephemeral and could disappear at any time. Read more about session storage in the [Security Guide](security.html). -- cgit v1.2.3 From c365986b48c3e8bc8c7f3fa6a8521616ed5dc138 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 18 Nov 2013 18:31:37 +0100 Subject: syntax error joining tables syntax error joining tables --- guides/source/active_record_querying.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 57e8e080f4..7d641b67ba 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -473,7 +473,7 @@ In the case of a belongs_to relationship, an association key can be used to spec ```ruby Post.where(author: author) -Author.joins(:posts).where(posts: {author: author}) +Author.joins(:post).where(posts: {author: author}) ``` NOTE: The values cannot be symbols. For example, you cannot do `Client.where(status: :active)`. @@ -975,7 +975,7 @@ Now all of the following will produce the expected join queries using `INNER JOI #### Joining a Single Association ```ruby -Category.joins(:posts) +Category.joins(:post) ``` This produces: @@ -990,7 +990,7 @@ Or, in English: "return a Category object for all categories with posts". Note t #### Joining Multiple Associations ```ruby -Post.joins(:category, :comments) +Post.joins(:category, :comment) ``` This produces: @@ -1041,14 +1041,14 @@ You can specify conditions on the joined tables using the regular [Array](#array ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:orders).where('orders.created_at' => time_range) +Client.joins(:order).where('orders.created_at' => time_range) ``` An alternative and cleaner syntax is to nest the hash conditions: ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:orders).where(orders: {created_at: time_range}) +Client.joins(:order).where(orders: {created_at: time_range}) ``` This will find all clients who have orders that were created yesterday, again using a `BETWEEN` SQL expression. -- cgit v1.2.3 From ac35f72f30c47298a20a90c8c537db888b463bbb Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 18 Nov 2013 18:39:06 +0100 Subject: syntax error joining/including models syntax error joining/including models --- guides/source/active_record_querying.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 7d641b67ba..0f9b2c28a5 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -1101,7 +1101,7 @@ Active Record lets you eager load any number of associations with a single `Mode #### Array of Multiple Associations ```ruby -Post.includes(:category, :comments) +Post.includes(:category, :comment) ``` This loads all the posts and the associated category and comments for each post. @@ -1121,7 +1121,7 @@ Even though Active Record lets you specify conditions on the eager loaded associ However if you must do this, you may use `where` as you would normally. ```ruby -Post.includes(:comments).where("comments.visible" => true) +Post.includes(:comment).where("comments.visible" => true) ``` This would generate a query which contains a `LEFT OUTER JOIN` whereas the `joins` method would generate one using the `INNER JOIN` function instead. -- cgit v1.2.3 From db3ec5183258fae55ba6d5335cbdbb82f61818b7 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 19 Nov 2013 10:46:34 -0200 Subject: Revert last two commits mistakenly changing join/include syntax --- Revert "syntax error joining/including models" This reverts commit ac35f72f30c47298a20a90c8c537db888b463bbb. --- Revert "syntax error joining tables" This reverts commit c365986b48c3e8bc8c7f3fa6a8521616ed5dc138. --- Comments: https://github.com/rails/docrails/commit/c365986b48c3e8bc8c7f3fa6a8521616ed5dc138#commitcomment-4630684 --- guides/source/active_record_querying.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 0f9b2c28a5..57e8e080f4 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -473,7 +473,7 @@ In the case of a belongs_to relationship, an association key can be used to spec ```ruby Post.where(author: author) -Author.joins(:post).where(posts: {author: author}) +Author.joins(:posts).where(posts: {author: author}) ``` NOTE: The values cannot be symbols. For example, you cannot do `Client.where(status: :active)`. @@ -975,7 +975,7 @@ Now all of the following will produce the expected join queries using `INNER JOI #### Joining a Single Association ```ruby -Category.joins(:post) +Category.joins(:posts) ``` This produces: @@ -990,7 +990,7 @@ Or, in English: "return a Category object for all categories with posts". Note t #### Joining Multiple Associations ```ruby -Post.joins(:category, :comment) +Post.joins(:category, :comments) ``` This produces: @@ -1041,14 +1041,14 @@ You can specify conditions on the joined tables using the regular [Array](#array ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:order).where('orders.created_at' => time_range) +Client.joins(:orders).where('orders.created_at' => time_range) ``` An alternative and cleaner syntax is to nest the hash conditions: ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:order).where(orders: {created_at: time_range}) +Client.joins(:orders).where(orders: {created_at: time_range}) ``` This will find all clients who have orders that were created yesterday, again using a `BETWEEN` SQL expression. @@ -1101,7 +1101,7 @@ Active Record lets you eager load any number of associations with a single `Mode #### Array of Multiple Associations ```ruby -Post.includes(:category, :comment) +Post.includes(:category, :comments) ``` This loads all the posts and the associated category and comments for each post. @@ -1121,7 +1121,7 @@ Even though Active Record lets you specify conditions on the eager loaded associ However if you must do this, you may use `where` as you would normally. ```ruby -Post.includes(:comment).where("comments.visible" => true) +Post.includes(:comments).where("comments.visible" => true) ``` This would generate a query which contains a `LEFT OUTER JOIN` whereas the `joins` method would generate one using the `INNER JOIN` function instead. -- cgit v1.2.3 From 20d3484f32f22b6775f3ff6e8983c5bc021855eb Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 19 Nov 2013 10:54:46 -0200 Subject: Improve reading / style of hashes in AR guide --- guides/source/active_record_querying.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.md b/guides/source/active_record_querying.md index 57e8e080f4..43160025f0 100644 --- a/guides/source/active_record_querying.md +++ b/guides/source/active_record_querying.md @@ -473,7 +473,7 @@ In the case of a belongs_to relationship, an association key can be used to spec ```ruby Post.where(author: author) -Author.joins(:posts).where(posts: {author: author}) +Author.joins(:posts).where(posts: { author: author }) ``` NOTE: The values cannot be symbols. For example, you cannot do `Client.where(status: :active)`. @@ -1022,7 +1022,7 @@ Or, in English: "return all posts that have a comment made by a guest." #### Joining Nested Associations (Multiple Level) ```ruby -Category.joins(posts: [{comments: :guest}, :tags]) +Category.joins(posts: [{ comments: :guest }, :tags]) ``` This produces: @@ -1048,7 +1048,7 @@ An alternative and cleaner syntax is to nest the hash conditions: ```ruby time_range = (Time.now.midnight - 1.day)..Time.now.midnight -Client.joins(:orders).where(orders: {created_at: time_range}) +Client.joins(:orders).where(orders: { created_at: time_range }) ``` This will find all clients who have orders that were created yesterday, again using a `BETWEEN` SQL expression. @@ -1109,7 +1109,7 @@ This loads all the posts and the associated category and comments for each post. #### Nested Associations Hash ```ruby -Category.includes(posts: [{comments: :guest}, :tags]).find(1) +Category.includes(posts: [{ comments: :guest }, :tags]).find(1) ``` This will find the category with id 1 and eager load all of the associated posts, the associated posts' tags and comments, and every comment's guest association. @@ -1610,7 +1610,7 @@ Client.where(first_name: 'Ryan').count You can also use various finder methods on a relation for performing complex calculations: ```ruby -Client.includes("orders").where(first_name: 'Ryan', orders: {status: 'received'}).count +Client.includes("orders").where(first_name: 'Ryan', orders: { status: 'received' }).count ``` Which will execute: -- cgit v1.2.3 From eb67aa976b42e4686274ead08031e465190d348d Mon Sep 17 00:00:00 2001 From: Harshad Sabne Date: Sat, 23 Nov 2013 10:45:07 +0530 Subject: API Documentation Guidelines link correction [ci skip] --- guides/source/ruby_on_rails_guides_guidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/ruby_on_rails_guides_guidelines.md b/guides/source/ruby_on_rails_guides_guidelines.md index 5564b0648b..8faf03e58c 100644 --- a/guides/source/ruby_on_rails_guides_guidelines.md +++ b/guides/source/ruby_on_rails_guides_guidelines.md @@ -51,7 +51,7 @@ Use the same typography as in regular text: API Documentation Guidelines ---------------------------- -The guides and the API should be coherent and consistent where appropriate. Please have a look at these particular sections of the [API Documentation Guidelines](api_documentation_guidelines.html:) +The guides and the API should be coherent and consistent where appropriate. Please have a look at these particular sections of the [API Documentation Guidelines](api_documentation_guidelines.html): * [Wording](api_documentation_guidelines.html#wording) * [Example Code](api_documentation_guidelines.html#example-code) -- cgit v1.2.3 From 28a6a7ea3bd627a8b6693a4cb8305b89467592b4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 24 Nov 2013 19:55:46 +0100 Subject: a couple of copy-edits before merging [ci skip] --- guides/source/initialization.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.md b/guides/source/initialization.md index f1bbb5bb13..5e2e0ad3e3 100644 --- a/guides/source/initialization.md +++ b/guides/source/initialization.md @@ -128,8 +128,7 @@ A standard Rails application depends on several gems, specifically: Once `config/boot.rb` has finished, the next file that is required is `rails/commands`, which helps in expanding aliases. In the current case, the -`ARGV` array simply contains `server` which will be passed over to -`rails/commands_tasks`. +`ARGV` array simply contains `server` which will be passed over: ```ruby ARGV << '--help' if ARGV.empty? @@ -160,7 +159,7 @@ defined here to find the matching command. ### `rails/commands/command_tasks.rb` When one types an incorrect rails command, the `run_command` is responsible for -throwing an error message. If the command is valid, a function of the same name +throwing an error message. If the command is valid, a method of the same name is called. ```ruby -- cgit v1.2.3