From da0ef60d3b9dd226d24465741eca47bde97745e5 Mon Sep 17 00:00:00 2001 From: Erich Menge Date: Wed, 30 May 2012 12:48:57 -0500 Subject: Fix typo [ci skip] --- activesupport/lib/active_support/json/encoding.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index ded02c873a..59709a19f1 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -192,7 +192,7 @@ end class Float # Encoding Infinity or NaN to JSON should return "null". The default returns - # "Infinity" or "NaN" breaks parsing the JSON. E.g. JSON.parse('[NaN]'). + # "Infinity" or "NaN" which breaks parsing the JSON. E.g. JSON.parse('[NaN]'). def as_json(options = nil) finite? ? self : nil end #:nodoc: end -- cgit v1.2.3 From f87820d00acc4a699f2bb405fa33d4f1054ec52d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 31 May 2012 05:06:00 -0500 Subject: update ActiveModel::Dirty documentation --- activemodel/lib/active_model/dirty.rb | 59 +++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 3f2fd12db7..7014d8114f 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -11,14 +11,14 @@ module ActiveModel # # The requirements for implementing ActiveModel::Dirty are: # - # * include ActiveModel::Dirty in your object + # * include ActiveModel::Dirty in your object. # * Call define_attribute_methods passing each method you want to - # track + # track. # * Call attr_name_will_change! before each change to the tracked - # attribute + # attribute. # # If you wish to also track previous changes on save or update, you need to - # add + # add: # # @previously_changed = changes # @@ -27,7 +27,6 @@ module ActiveModel # A minimal implementation could be: # # class Person - # # include ActiveModel::Dirty # # define_attribute_methods :name @@ -45,47 +44,49 @@ module ActiveModel # @previously_changed = changes # @changed_attributes.clear # end - # # end # - # == Examples: - # # A newly instantiated object is unchanged: + # # person = Person.find_by_name('Uncle Bob') # person.changed? # => false # # Change the name: + # # person.name = 'Bob' # person.changed? # => true # person.name_changed? # => true - # person.name_was # => 'Uncle Bob' - # person.name_change # => ['Uncle Bob', 'Bob'] + # person.name_was # => "Uncle Bob" + # person.name_change # => ["Uncle Bob", "Bob"] # person.name = 'Bill' - # person.name_change # => ['Uncle Bob', 'Bill'] + # person.name_change # => ["Uncle Bob", "Bill"] # # Save the changes: + # # person.save # person.changed? # => false # person.name_changed? # => false # # Assigning the same value leaves the attribute unchanged: + # # person.name = 'Bill' # person.name_changed? # => false # person.name_change # => nil # # Which attributes have changed? + # # person.name = 'Bob' - # person.changed # => ['name'] - # person.changes # => { 'name' => ['Bill', 'Bob'] } + # person.changed # => ["name"] + # person.changes # => {"name" => ["Bill", "Bob"]} # # If an attribute is modified in-place then make use of [attribute_name]_will_change! # to mark that the attribute is changing. Otherwise ActiveModel can't track changes to # in-place attributes. # # person.name_will_change! - # person.name_change # => ['Bill', 'Bill'] + # person.name_change # => ["Bill", "Bill"] # person.name << 'y' - # person.name_change # => ['Bill', 'Billy'] + # person.name_change # => ["Bill", "Billy"] module Dirty extend ActiveSupport::Concern include ActiveModel::AttributeMethods @@ -95,7 +96,8 @@ module ActiveModel attribute_method_affix :prefix => 'reset_', :suffix => '!' end - # Returns true if any attribute have unsaved changes, false otherwise. + # Returns +true+ if any attribute have unsaved changes, +false+ otherwise. + # # person.changed? # => false # person.name = 'bob' # person.changed? # => true @@ -103,32 +105,41 @@ module ActiveModel changed_attributes.present? end - # List of attributes with unsaved changes. + # Returns an array with the name of the attributes with unsaved changes. + # # person.changed # => [] # person.name = 'bob' - # person.changed # => ['name'] + # person.changed # => ["name"] def changed changed_attributes.keys end - # Map of changed attrs => [original value, new value]. + # Returns a hash of changed attributes indicating their original + # and new values like attr => [original value, new value]. + # # person.changes # => {} # person.name = 'bob' - # person.changes # => { 'name' => ['bill', 'bob'] } + # person.changes # => { "name" => ["bill", "bob"] } def changes HashWithIndifferentAccess[changed.map { |attr| [attr, attribute_change(attr)] }] end - # Map of attributes that were changed when the model was saved. - # person.name # => 'bob' + # Returns a hash of attributes that were changed before the model was saved. + # + # person.name # => "bob" # person.name = 'robert' # person.save - # person.previous_changes # => {'name' => ['bob, 'robert']} + # person.previous_changes # => {"name" => ["bob", "robert"]} def previous_changes @previously_changed end - # Map of change attr => original value. + # Returns a hash of the attributes with unsaved changes indicating their original + # values like attr => original value. + # + # person.name # => "bob" + # person.name = 'robert' + # person.changed_attributes # => {"name" => "bob"} def changed_attributes @changed_attributes ||= {} end -- cgit v1.2.3 From e63666398d77fcca46308eff63dce144dd199479 Mon Sep 17 00:00:00 2001 From: schneems Date: Fri, 1 Jun 2012 16:44:41 +0200 Subject: routes are viewable in browser (update guides) From the Pull Request #6461 --- guides/source/routing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/source/routing.textile b/guides/source/routing.textile index 0773a96c67..6bd08185be 100644 --- a/guides/source/routing.textile +++ b/guides/source/routing.textile @@ -859,9 +859,9 @@ h3. Inspecting and Testing Routes Rails offers facilities for inspecting and testing your routes. -h4. Seeing Existing Routes with +rake+ +h4. Seeing Existing Routes -If you want a complete list of all of the available routes in your application, run +rake routes+ command. This will print all of your routes, in the same order that they appear in +routes.rb+. For each route, you'll see: +If you want a complete list of all of the available routes in your application, visit +http://localhost:3000/rails/info/routes+ in your browser while your server is running in the development environment. If your local server is not running, you can execute the +rake routes+ command in your terminal to produce the same output. This will print all of your routes, in the same order that they appear in +routes.rb+. For each route, you'll see: * The route name (if any) * The HTTP verb used (if the route doesn't respond to all verbs) -- cgit v1.2.3 From b4f1c169089f7e9048dcbe7b38923f3162af6cce Mon Sep 17 00:00:00 2001 From: spyhole Date: Sat, 2 Jun 2012 12:17:13 +0800 Subject: Update guides/code/getting_started/config/routes.rb --- guides/code/getting_started/config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/code/getting_started/config/routes.rb b/guides/code/getting_started/config/routes.rb index 04a6bd374e..a494d010a6 100644 --- a/guides/code/getting_started/config/routes.rb +++ b/guides/code/getting_started/config/routes.rb @@ -53,7 +53,7 @@ Blog::Application.routes.draw do # You can have the root of your site routed with "root" # just remember to delete public/index.html. - root :to => "welcome#index" + root :to => "home#index" # See how all your routes lay out with "rake routes" -- cgit v1.2.3 From 81281befb2d85a1d59f8cdf1ef6bbb7e206df2a4 Mon Sep 17 00:00:00 2001 From: spyhole Date: Sat, 2 Jun 2012 12:17:48 +0800 Subject: Update guides/code/getting_started/app/controllers/home_controller.rb --- guides/code/getting_started/app/controllers/home_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/code/getting_started/app/controllers/home_controller.rb b/guides/code/getting_started/app/controllers/home_controller.rb index 309b70441e..6cc31c1ca3 100644 --- a/guides/code/getting_started/app/controllers/home_controller.rb +++ b/guides/code/getting_started/app/controllers/home_controller.rb @@ -1,4 +1,4 @@ -class WelcomeController < ApplicationController +class HomeController < ApplicationController def index end -- cgit v1.2.3 From 890c4b7778335d1f3c4693bd52d9a07b3c0fa40e Mon Sep 17 00:00:00 2001 From: spyhole Date: Sat, 2 Jun 2012 13:20:17 +0800 Subject: the file name should be changed to home_helper.rb --- guides/code/getting_started/app/helpers/welcome_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/code/getting_started/app/helpers/welcome_helper.rb b/guides/code/getting_started/app/helpers/welcome_helper.rb index eeead45fc9..23de56ac60 100644 --- a/guides/code/getting_started/app/helpers/welcome_helper.rb +++ b/guides/code/getting_started/app/helpers/welcome_helper.rb @@ -1,2 +1,2 @@ -module WelcomeHelper +module HomeHelper end -- cgit v1.2.3 From f82066886780a9d5290cd3cfc3335c5798bfea57 Mon Sep 17 00:00:00 2001 From: spyhole Date: Sat, 2 Jun 2012 13:33:39 +0800 Subject: Update guides/code/getting_started/test/functional/home_controller_test.rb --- guides/code/getting_started/test/functional/home_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/code/getting_started/test/functional/home_controller_test.rb b/guides/code/getting_started/test/functional/home_controller_test.rb index dff8e9d2c5..0d9bb47c3e 100644 --- a/guides/code/getting_started/test/functional/home_controller_test.rb +++ b/guides/code/getting_started/test/functional/home_controller_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class WelcomeControllerTest < ActionController::TestCase +class HomeControllerTest < ActionController::TestCase test "should get index" do get :index assert_response :success -- cgit v1.2.3 From cd31eb19dd5accb02335d998d1031ac5a223cb34 Mon Sep 17 00:00:00 2001 From: spyhole Date: Fri, 1 Jun 2012 02:56:42 -0400 Subject: change welcome_helper.rb to home_helper.rb --- guides/code/getting_started/app/helpers/home_helper.rb | 2 ++ guides/code/getting_started/app/helpers/welcome_helper.rb | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 guides/code/getting_started/app/helpers/home_helper.rb delete mode 100644 guides/code/getting_started/app/helpers/welcome_helper.rb diff --git a/guides/code/getting_started/app/helpers/home_helper.rb b/guides/code/getting_started/app/helpers/home_helper.rb new file mode 100644 index 0000000000..23de56ac60 --- /dev/null +++ b/guides/code/getting_started/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/guides/code/getting_started/app/helpers/welcome_helper.rb b/guides/code/getting_started/app/helpers/welcome_helper.rb deleted file mode 100644 index 23de56ac60..0000000000 --- a/guides/code/getting_started/app/helpers/welcome_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module HomeHelper -end -- cgit v1.2.3 From faf550c1916550d62e64366d04a5222a5751d05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?= Date: Sat, 2 Jun 2012 15:04:35 +0200 Subject: better explanations for acts_like?, try and deep_dup --- .../source/active_support_core_extensions.textile | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 2addc50d68..65fb4d09b4 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -156,7 +156,7 @@ NOTE: Defined in +active_support/core_ext/object/duplicable.rb+. h4. +deep_dup+ -The +deep_dup+ method returns deep copy of given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have array with a string, for example, it will look like this: +The +deep_dup+ method returns deep copy of a given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have array with a string, for example, it will look like this: array = ['string'] @@ -164,7 +164,7 @@ duplicate = array.dup duplicate.push 'another-string' -# object was duplicated, element added only to duplicate +# object was duplicated, so element was added only to duplicate array #=> ['string'] duplicate #=> ['string', 'another-string'] @@ -177,7 +177,7 @@ duplicate #=> ['foo', 'another-string'] As you can see, after duplicating +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 array is still the same object. -If you need a deep copy of an object, you should use +deep_dup+ in such situation: +If you need a deep copy of an object, you should use +deep_dup+. Here is an example: array = ['string'] @@ -201,9 +201,23 @@ NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+. h4. +try+ -Sometimes you want to call a method provided the receiver object is not +nil+, which is something you usually check first. +try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+. +There are a lot of situations where you want to call a method on the receiver object if the object is not +nil+, so your code remains safe from unhandled +NoMethodError+ exceptions. The simplest way to achieve this is with conditional statements, which add unnecessary clutter. The alternative is to +use +try+. -For instance, in this code from +ActiveRecord::ConnectionAdapters::AbstractAdapter+ +@logger+ could be +nil+, but you save the check and write in an optimistic style: ++try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+. + +Here is an example: + +# without try +unless @number.nil? + @number.next +end + +# with try +@number.try(:next) + + +Another example is this code from +ActiveRecord::ConnectionAdapters::AbstractAdapter+ +@logger+ could be +nil+, but you don't check it and write in an optimistic style: def log_info(sql, name, ms) @@ -245,7 +259,7 @@ NOTE: Defined in +active_support/core_ext/kernel/singleton_class.rb+. h4. +acts_like?(duck)+ -The method +acts_like+ provides a way to check whether some class acts like some other class based on a simple convention: a class that provides the same interface as +String+ defines +The method +acts_like?+ provides a way to check whether some class acts like some other class based on a simple convention: a class that provides the same interface as +String+ defines def acts_like_string? -- cgit v1.2.3 From 983687a9e55915c22b84b60b45ca2b40794cf9a2 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 2 Jun 2012 21:38:32 +0530 Subject: fix up the example app for getting started guide [ci skip] --- guides/code/getting_started/app/controllers/home_controller.rb | 5 ----- .../code/getting_started/app/controllers/welcome_controller.rb | 4 ++++ guides/code/getting_started/app/helpers/home_helper.rb | 2 -- guides/code/getting_started/app/helpers/welcome_helper.rb | 2 ++ guides/code/getting_started/config/routes.rb | 2 +- .../code/getting_started/test/functional/home_controller_test.rb | 9 --------- .../getting_started/test/functional/welcome_controller_test.rb | 8 ++++++++ 7 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 guides/code/getting_started/app/controllers/home_controller.rb create mode 100644 guides/code/getting_started/app/controllers/welcome_controller.rb delete mode 100644 guides/code/getting_started/app/helpers/home_helper.rb create mode 100644 guides/code/getting_started/app/helpers/welcome_helper.rb delete mode 100644 guides/code/getting_started/test/functional/home_controller_test.rb create mode 100644 guides/code/getting_started/test/functional/welcome_controller_test.rb diff --git a/guides/code/getting_started/app/controllers/home_controller.rb b/guides/code/getting_started/app/controllers/home_controller.rb deleted file mode 100644 index 6cc31c1ca3..0000000000 --- a/guides/code/getting_started/app/controllers/home_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class HomeController < ApplicationController - def index - end - -end diff --git a/guides/code/getting_started/app/controllers/welcome_controller.rb b/guides/code/getting_started/app/controllers/welcome_controller.rb new file mode 100644 index 0000000000..f9b859b9c9 --- /dev/null +++ b/guides/code/getting_started/app/controllers/welcome_controller.rb @@ -0,0 +1,4 @@ +class WelcomeController < ApplicationController + def index + end +end diff --git a/guides/code/getting_started/app/helpers/home_helper.rb b/guides/code/getting_started/app/helpers/home_helper.rb deleted file mode 100644 index 23de56ac60..0000000000 --- a/guides/code/getting_started/app/helpers/home_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module HomeHelper -end diff --git a/guides/code/getting_started/app/helpers/welcome_helper.rb b/guides/code/getting_started/app/helpers/welcome_helper.rb new file mode 100644 index 0000000000..eeead45fc9 --- /dev/null +++ b/guides/code/getting_started/app/helpers/welcome_helper.rb @@ -0,0 +1,2 @@ +module WelcomeHelper +end diff --git a/guides/code/getting_started/config/routes.rb b/guides/code/getting_started/config/routes.rb index a494d010a6..04a6bd374e 100644 --- a/guides/code/getting_started/config/routes.rb +++ b/guides/code/getting_started/config/routes.rb @@ -53,7 +53,7 @@ Blog::Application.routes.draw do # You can have the root of your site routed with "root" # just remember to delete public/index.html. - root :to => "home#index" + root :to => "welcome#index" # See how all your routes lay out with "rake routes" diff --git a/guides/code/getting_started/test/functional/home_controller_test.rb b/guides/code/getting_started/test/functional/home_controller_test.rb deleted file mode 100644 index 0d9bb47c3e..0000000000 --- a/guides/code/getting_started/test/functional/home_controller_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' - -class HomeControllerTest < ActionController::TestCase - test "should get index" do - get :index - assert_response :success - end - -end diff --git a/guides/code/getting_started/test/functional/welcome_controller_test.rb b/guides/code/getting_started/test/functional/welcome_controller_test.rb new file mode 100644 index 0000000000..e4d5abae11 --- /dev/null +++ b/guides/code/getting_started/test/functional/welcome_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class WelcomeControllerTest < ActionController::TestCase + test "should get index" do + get :index + assert_response :success + end +end -- cgit v1.2.3 From 313c528e0b7343338864941b4391ec11d308935b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 2 Jun 2012 21:46:28 +0530 Subject: copy edit routing guide [ci skip] --- guides/source/routing.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/guides/source/routing.textile b/guides/source/routing.textile index 6bd08185be..7941e655bb 100644 --- a/guides/source/routing.textile +++ b/guides/source/routing.textile @@ -861,7 +861,9 @@ Rails offers facilities for inspecting and testing your routes. h4. Seeing Existing Routes -If you want a complete list of all of the available routes in your application, visit +http://localhost:3000/rails/info/routes+ in your browser while your server is running in the development environment. If your local server is not running, you can execute the +rake routes+ command in your terminal to produce the same output. This will print all of your routes, in the same order that they appear in +routes.rb+. For each route, you'll see: +To get a complete list of the available routes in your application, visit +http://localhost:3000/rails/info/routes+ in your browser while your server is running in the *development* environment. You can also execute the +rake routes+ command in your terminal to produce the same output. + +Both methods will list all of your routes, in the same order that they appear in +routes.rb+. For each route, you'll see: * The route name (if any) * The HTTP verb used (if the route doesn't respond to all verbs) -- cgit v1.2.3 From ab2bf8148c8000a5185b11b6c1b11d94ae33053d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 2 Jun 2012 21:46:39 +0530 Subject: copy edit AS guide [ci skip] --- guides/source/active_support_core_extensions.textile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 65fb4d09b4..011a702901 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -156,7 +156,7 @@ NOTE: Defined in +active_support/core_ext/object/duplicable.rb+. h4. +deep_dup+ -The +deep_dup+ method returns deep copy of a given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have array with a string, for example, it will look like this: +The +deep_dup+ method returns deep copy of a given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have an array with a string, for example, it will look like this: array = ['string'] @@ -189,7 +189,7 @@ array #=> ['string'] duplicate #=> ['foo'] -If object is not duplicable +deep_dup+ will just return this object: +If object is not duplicable, +deep_dup+ will just return this object: number = 1 @@ -201,12 +201,10 @@ NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+. h4. +try+ -There are a lot of situations where you want to call a method on the receiver object if the object is not +nil+, so your code remains safe from unhandled +NoMethodError+ exceptions. The simplest way to achieve this is with conditional statements, which add unnecessary clutter. The alternative is to -use +try+. - -+try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+. +When you want to call a method on an object only if it is not +nil+, the simplest way to achieve it is with conditional statements, adding unnecessary clutter. The alternative is to use +try+. +try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+. Here is an example: + # without try unless @number.nil? @@ -217,7 +215,7 @@ end @number.try(:next) -Another example is this code from +ActiveRecord::ConnectionAdapters::AbstractAdapter+ +@logger+ could be +nil+, but you don't check it and write in an optimistic style: +Another example is this code from +ActiveRecord::ConnectionAdapters::AbstractAdapter+ where +@logger+ could be +nil+. You can see that the code uses +try+ and avoids an unnecessary check. def log_info(sql, name, ms) -- cgit v1.2.3