From 983a2dccaa263bad1f055a85d864a8097f0af8a2 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Thu, 10 Nov 2011 09:45:57 +0400 Subject: [PATCH 01/36] Cosmetic fix in number_to_currency docs --- actionpack/lib/action_view/helpers/number_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 7031694af4..e8ad043e20 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -100,10 +100,10 @@ module ActionView # number_to_currency(1234567890.50) # => $1,234,567,890.50 # number_to_currency(1234567890.506) # => $1,234,567,890.51 # number_to_currency(1234567890.506, :precision => 3) # => $1,234,567,890.506 - # number_to_currency(1234567890.506, :locale => :fr) # => 1 234 567 890,506 € + # number_to_currency(1234567890.506, :locale => :fr) # => 1 234 567 890,51 € # # number_to_currency(-1234567890.50, :negative_format => "(%u%n)") - # # => ($1,234,567,890.51) + # # => ($1,234,567,890.50) # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "") # # => £1234567890,50 # number_to_currency(1234567890.50, :unit => "£", :separator => ",", :delimiter => "", :format => "%n %u") From fd17ffc7a27c2fc5c3c2afb82c9e1909fd5ba7a1 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 10 Nov 2011 18:49:37 +0100 Subject: [PATCH 02/36] Fix a tiny typo in custom validators documentation --- activemodel/lib/active_model/validations/validates.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index fbceb81e8f..8e09f6ac35 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/activemodel/lib/active_model/validations/validates.rb @@ -57,7 +57,7 @@ module ActiveModel # # Additionally validator classes may be in another namespace and still used within any class. # - # validates :name, :'file/title' => true + # validates :name, :'film/title' => true # # The validators hash can also handle regular expressions, ranges, # arrays and strings in shortcut form, e.g. From 9ce5d5155bc394fbd076203b14fbd8d83d10caf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Thu, 10 Nov 2011 18:52:39 +0100 Subject: [PATCH 03/36] fixed example code indentation --- railties/lib/rails/engine.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 1c9627734e..d652c6b7fe 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -296,16 +296,16 @@ module Rails # If you want to share just a few specific helpers you can add them to application's # helpers in ApplicationController: # - # class ApplicationController < ActionController::Base - # helper MyEngine::SharedEngineHelper - # end + # class ApplicationController < ActionController::Base + # helper MyEngine::SharedEngineHelper + # end # # If you want to include all of the engine's helpers, you can use #helpers method on an engine's # instance: # - # class ApplicationController < ActionController::Base - # helper MyEngine::Engine.helpers - # end + # class ApplicationController < ActionController::Base + # helper MyEngine::Engine.helpers + # end # # It will include all of the helpers from engine's directory. Take into account that this does # not include helpers defined in controllers with helper_method or other similar solutions, From b9aaa317cfa56a68b406181a93d9e11b8560f9a1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 11 Nov 2011 01:49:05 +0530 Subject: [PATCH 04/36] update ci file name in contributing guide --- railties/guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index 4d84c50e2a..80c3cf6e1a 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -200,7 +200,7 @@ $ bundle exec rake test will now run the four of them in turn. -You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_jdbcpostgresql+. Check out the file +activerecord/RUNNING_UNIT_TESTS+ for information on running more targeted database tests, or the file +ci/ci_build.rb+ to see the test suite that the continuous integration server runs. +You can also invoke +test_jdbcmysql+, +test_jdbcsqlite3+ or +test_jdbcpostgresql+. Check out the file +activerecord/RUNNING_UNIT_TESTS+ for information on running more targeted database tests, or the file +ci/travis.rb+ to see the test suite that the continuous integration server runs. h4. Older versions of Ruby on Rails From e34e4d43301618307f94123d3710f094297f91f3 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Fri, 11 Nov 2011 17:04:50 +0800 Subject: [PATCH 05/36] Fix "in memory" where it should be "in-memory". --- activerecord/test/cases/nested_attributes_test.rb | 4 ++-- activerecord/test/cases/relation_scoping_test.rb | 2 +- activesupport/lib/active_support/cache/file_store.rb | 2 +- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- .../lib/active_support/cache/strategy/local_cache.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 2ae9cb4888..532d4654b5 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -937,13 +937,13 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR @trinket = @part.trinkets.create!(:name => "Necklace") end - test "if association is not loaded and association record is saved and then in memory record attributes should be saved" do + test "if association is not loaded and association record is saved and then in-memory record attributes should be saved" do @ship.parts_attributes=[{:id => @part.id,:name =>'Deck'}] assert_equal 1, @ship.association(:parts).target.size assert_equal 'Deck', @ship.parts[0].name end - test "if association is not loaded and child doesn't change and I am saving a grandchild then in memory record should be used" do + test "if association is not loaded and child doesn't change and I am saving a grandchild then in-memory record should be used" do @ship.parts_attributes=[{:id => @part.id,:trinkets_attributes =>[{:id => @trinket.id, :name => 'Ruby'}]}] assert_equal 1, @ship.association(:parts).target.size assert_equal 'Mast', @ship.parts[0].name diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index 1e2093273e..ec1a6eda0c 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -527,7 +527,7 @@ class DefaultScopingTest < ActiveRecord::TestCase def test_default_scope_is_threadsafe if in_memory_db? - skip "in memory db can't share a db between threads" + skip "in-memory db can't share a db between threads" end threads = [] diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 85e7e21624..9460532af0 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class FileStore < Store attr_reader :cache_path diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index e07294178b..5234cdb4ce 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -21,7 +21,7 @@ module ActiveSupport # server goes down, then MemCacheStore will ignore it until it comes back up. # # MemCacheStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class MemCacheStore < Store module Response # :nodoc: STORED = "STORED\r\n" diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 0649a058aa..db5f228a70 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -4,9 +4,9 @@ require 'active_support/core_ext/string/inflections' module ActiveSupport module Cache module Strategy - # Caches that implement LocalCache will be backed by an in memory cache for the + # Caches that implement LocalCache will be backed by an in-memory cache for the # duration of a block. Repeated calls to the cache for the same key will hit the - # in memory cache for faster access. + # in-memory cache for faster access. module LocalCache # Simple memory backed cache. This cache is not thread safe and is intended only # for serving as a temporary memory cache for a single thread. From df5c9fd9f42e9bebb02bb61acf70de3d17bc8152 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Fri, 11 Nov 2011 17:07:02 +0800 Subject: [PATCH 06/36] Update Memcached website to its new one at http://memcached.org/. --- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 5234cdb4ce..530839b24d 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -11,7 +11,7 @@ require 'active_support/core_ext/string/encoding' module ActiveSupport module Cache # A cache store implementation which stores data in Memcached: - # http://www.danga.com/memcached/ + # http://memcached.org/ # # This is currently the most popular cache store for production websites. # From 9fd0cd3a12f969ca0c5c7ce6163e9e451637506d Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 11 Nov 2011 17:12:42 +0530 Subject: [PATCH 07/36] Revert "Fix "in memory" where it should be "in-memory"." This reverts commit e34e4d43301618307f94123d3710f094297f91f3. Reason: code changes are not allowed in docrails. --- activerecord/test/cases/nested_attributes_test.rb | 4 ++-- activerecord/test/cases/relation_scoping_test.rb | 2 +- activesupport/lib/active_support/cache/file_store.rb | 2 +- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- .../lib/active_support/cache/strategy/local_cache.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 532d4654b5..2ae9cb4888 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -937,13 +937,13 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR @trinket = @part.trinkets.create!(:name => "Necklace") end - test "if association is not loaded and association record is saved and then in-memory record attributes should be saved" do + test "if association is not loaded and association record is saved and then in memory record attributes should be saved" do @ship.parts_attributes=[{:id => @part.id,:name =>'Deck'}] assert_equal 1, @ship.association(:parts).target.size assert_equal 'Deck', @ship.parts[0].name end - test "if association is not loaded and child doesn't change and I am saving a grandchild then in-memory record should be used" do + test "if association is not loaded and child doesn't change and I am saving a grandchild then in memory record should be used" do @ship.parts_attributes=[{:id => @part.id,:trinkets_attributes =>[{:id => @trinket.id, :name => 'Ruby'}]}] assert_equal 1, @ship.association(:parts).target.size assert_equal 'Mast', @ship.parts[0].name diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index ec1a6eda0c..1e2093273e 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -527,7 +527,7 @@ class DefaultScopingTest < ActiveRecord::TestCase def test_default_scope_is_threadsafe if in_memory_db? - skip "in-memory db can't share a db between threads" + skip "in memory db can't share a db between threads" end threads = [] diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 9460532af0..85e7e21624 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in-memory cache inside of a block. + # an in memory cache inside of a block. class FileStore < Store attr_reader :cache_path diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 530839b24d..ba37f3e871 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -21,7 +21,7 @@ module ActiveSupport # server goes down, then MemCacheStore will ignore it until it comes back up. # # MemCacheStore implements the Strategy::LocalCache strategy which implements - # an in-memory cache inside of a block. + # an in memory cache inside of a block. class MemCacheStore < Store module Response # :nodoc: STORED = "STORED\r\n" diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index db5f228a70..0649a058aa 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -4,9 +4,9 @@ require 'active_support/core_ext/string/inflections' module ActiveSupport module Cache module Strategy - # Caches that implement LocalCache will be backed by an in-memory cache for the + # Caches that implement LocalCache will be backed by an in memory cache for the # duration of a block. Repeated calls to the cache for the same key will hit the - # in-memory cache for faster access. + # in memory cache for faster access. module LocalCache # Simple memory backed cache. This cache is not thread safe and is intended only # for serving as a temporary memory cache for a single thread. From 84908fa38264ea6de55fb7a858b4af7b64bb6efa Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Fri, 11 Nov 2011 13:34:55 -0500 Subject: [PATCH 08/36] For what it's worth; Update `memcache-client` gem name --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 4273d0dd64..5bf2284230 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -293,7 +293,7 @@ Note that the cache will grow until the disk is full unless you periodically cle h4. ActiveSupport::Cache::MemCacheStore -This cache store uses Danga's +memcached+ server to provide a centralized cache for your application. Rails uses the bundled +memcached-client+ gem by default. This is currently the most popular cache store for production websites. It can be used to provide a single, shared cache cluster with very a high performance and redundancy. +This cache store uses Danga's +memcached+ server to provide a centralized cache for your application. Rails uses the bundled +memcache-client+ gem by default. This is currently the most popular cache store for production websites. It can be used to provide a single, shared cache cluster with very a high performance and redundancy. When initializing the cache, you need to specify the addresses for all memcached servers in your cluster. If none is specified, it will assume memcached is running on the local host on the default port, but this is not an ideal set up for larger sites. From a02b40a3d28c4b262dd49a8a6166c0275dfd9964 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 13 Nov 2011 13:18:55 +0800 Subject: [PATCH 09/36] Fix "in memory" where it should be "in-memory". --- activesupport/lib/active_support/cache/file_store.rb | 2 +- activesupport/lib/active_support/cache/mem_cache_store.rb | 2 +- .../lib/active_support/cache/strategy/local_cache.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 85e7e21624..9460532af0 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -8,7 +8,7 @@ module ActiveSupport # A cache store implementation which stores everything on the filesystem. # # FileStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class FileStore < Store attr_reader :cache_path diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index ba37f3e871..530839b24d 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -21,7 +21,7 @@ module ActiveSupport # server goes down, then MemCacheStore will ignore it until it comes back up. # # MemCacheStore implements the Strategy::LocalCache strategy which implements - # an in memory cache inside of a block. + # an in-memory cache inside of a block. class MemCacheStore < Store module Response # :nodoc: STORED = "STORED\r\n" diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 0649a058aa..db5f228a70 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -4,9 +4,9 @@ require 'active_support/core_ext/string/inflections' module ActiveSupport module Cache module Strategy - # Caches that implement LocalCache will be backed by an in memory cache for the + # Caches that implement LocalCache will be backed by an in-memory cache for the # duration of a block. Repeated calls to the cache for the same key will hit the - # in memory cache for faster access. + # in-memory cache for faster access. module LocalCache # Simple memory backed cache. This cache is not thread safe and is intended only # for serving as a temporary memory cache for a single thread. From 650ec898e5f4668b63925d05f8b722a5226a79dd Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 13 Nov 2011 13:25:39 +0800 Subject: [PATCH 10/36] Suggest a workaround for page caching and parameters instead of an unhelpful warning. --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 5bf2284230..972579b453 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -64,7 +64,7 @@ end If you want a more complicated expiration scheme, you can use cache sweepers to expire cached objects when things change. This is covered in the section on Sweepers. -NOTE: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. Be careful when page caching GET parameters in the URL! +NOTE: Page caching ignores all parameters. For example +/products?page=1+ will be written out to the filesystem as +products.html+ with no reference to the +page+ parameter. Thus, if someone requests +/products?page=2+ later, they will get the cached first page. A workaround for this limitation is to include the parameters in the page's path, e.g. +/productions/page/1+. INFO: Page caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job. From d9703fe92ea0d39eed7bec44027468e6fed70a8a Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 13 Nov 2011 13:34:16 +0800 Subject: [PATCH 11/36] Clearing cache in action caching is not "the exact same way" as with page caching. --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 972579b453..aa08148bdb 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -72,7 +72,7 @@ h4. Action Caching One of the issues with Page Caching is that you cannot use it for pages that require to restrict access somehow. This is where Action Caching comes in. Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served. This allows authentication and other restriction to be run while still serving the result of the output from a cached copy. -Clearing the cache works in the exact same way as with Page Caching. +Clearing the cache works in a similar way to Page Caching, except you use the +expire_action+ instead of +expire_page+. Let's say you only wanted authenticated users to call actions on +ProductsController+. From f323b425f29b633e07441cbc97fcbecf7e4b61a8 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 13 Nov 2011 13:35:32 +0800 Subject: [PATCH 12/36] Fix bad English. --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index aa08148bdb..0ef6f51190 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -72,7 +72,7 @@ h4. Action Caching One of the issues with Page Caching is that you cannot use it for pages that require to restrict access somehow. This is where Action Caching comes in. Action Caching works like Page Caching except for the fact that the incoming web request does go from the webserver to the Rails stack and Action Pack so that before filters can be run on it before the cache is served. This allows authentication and other restriction to be run while still serving the result of the output from a cached copy. -Clearing the cache works in a similar way to Page Caching, except you use the +expire_action+ instead of +expire_page+. +Clearing the cache works in a similar way to Page Caching, except you use +expire_action+ instead of +expire_page+. Let's say you only wanted authenticated users to call actions on +ProductsController+. From 962c55de0d24561d54babe5608630f93afc2681f Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:16:58 -0700 Subject: [PATCH 13/36] Add Tip about skipping to Section 3 if they want to come back to the philosophy later --- railties/guides/source/getting_started.textile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index bf6104b96b..ce556a0f87 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -46,6 +46,10 @@ in rails/railties/guides/code/getting_started. h3. What is Rails? +TIP: This section goes into the background and philosophy of the Rails framework +in detail. You can safely skip this section and come back to it at a later time. +Section 3 starts you on the path to creating your first Rails application. + Rails is a web application development framework written in the Ruby language. It is designed to make programming web applications easier by making assumptions about what every developer needs to get started. It allows you to write less From ee100128c3a917f96d6f40293bb5a5ed3bcf8c27 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:18:24 -0700 Subject: [PATCH 14/36] Move paragraphs to flow better - Give the user a way to know they are fully installed and ready to continue --- .../guides/source/getting_started.textile | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index ce556a0f87..447b8e86d0 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -219,7 +219,12 @@ Ian Robinson h3. Creating a New Rails Project -If you follow this guide, you'll create a Rails project called blog, a +The best way to use this guide is to follow each step as it happens, no code or +step needed to make this example application has been left out, so you can +literally follow along step by step. If you need to see the completed code, you +can download it from "Getting Started Code":https://github.com/mikel/getting-started-code. + +By following along with this guide, you'll create a Rails project called blog, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed. @@ -237,13 +242,16 @@ Usually run this as the root user: TIP. If you're working on Windows, you can quickly install Ruby and Rails with "Rails Installer":http://railsinstaller.org. -h4. Creating the Blog Application +To verify that you have everything installed correctly, you should be able to run +the following: -The best way to use this guide is to follow each step as it happens, no code or -step needed to make this example application has been left out, so you can -literally follow along step by step. If you need to see the completed code, you -can download it from "Getting Started -Code":https://github.com/mikel/getting-started-code. + +# rails --version + + +If it says something like "Rails 3.1.1" you are ready to continue. + +h4. Creating the Blog Application To begin, open a terminal, navigate to a folder where you have rights to create files, and type: From 6ac65c92029d3eefd101f9458d86bae0314cd14c Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:19:21 -0700 Subject: [PATCH 15/36] Use rails help new instead of rails new -h --- railties/guides/source/getting_started.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 447b8e86d0..b9a0f6a8ba 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -263,8 +263,7 @@ $ rails new blog This will create a Rails application called Blog in a directory called blog. TIP: You can see all of the switches that the Rails application builder accepts -by running -rails new -h. +by running rails help new. After you create the blog application, switch to its folder to continue work directly in that application: From b778a7eefbf755f5f131b5af06a4c555628075a9 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:21:40 -0700 Subject: [PATCH 16/36] Updated wording on what 'rails new blog' did for the user - Alphabetized the files/folders created - Added link to Configuring Rails Applications --- .../guides/source/getting_started.textile | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index b9a0f6a8ba..dfd27459b4 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -272,28 +272,28 @@ directly in that application: $ cd blog -In any case, Rails will create a folder in your working directory called -blog. Open up that folder and explore its contents. Most of the work in +The 'rails new blog' command we ran above created a folder in your working directory +called blog. The blog folder has a number of auto-generated folders +that make up the structure of a Rails application. Most of the work in this tutorial will happen in the app/ folder, but here's a basic -rundown on the function of each folder that Rails creates in a new application -by default: +rundown on the function of each of the files and folders that Rails created by default: |_.File/Folder|_.Purpose| -|Gemfile|This file allows you to specify what gem dependencies are needed for your Rails application. See section on Bundler, below.| -|README|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.| -|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.| |app/|Contains the controllers, models, views and assets for your application. You'll focus on this folder for the remainder of this guide.| -|config/|Configure your application's runtime rules, routes, database, and more.| +|config/|Configure your application's runtime rules, routes, database, and more. This is covered in more detail in "Configuring Rails Applications":configuring.html| |config.ru|Rack configuration for Rack based servers used to start the application.| -|db/|Shows your current database schema, as well as the database migrations. You'll learn about migrations shortly.| +|db/|Contains your current database schema, as well as the database migrations.| |doc/|In-depth documentation for your application.| -|lib/|Extended modules for your application (not covered in this guide).| +|Gemfile
Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application.| +|lib/|Extended modules for your application.| |log/|Application log files.| |public/|The only folder seen to the world as-is. Contains the static files and compiled assets.| +|Rakefile|This file locates and loads tasks that can be run from the command line. The task definitions are defined throughout the components of Rails. Rather than changing Rakefile, you should add your own tasks by adding files to the lib/tasks directory of your application.| +|README|This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.| |script/|Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application.| |test/|Unit tests, fixtures, and other test apparatus. These are covered in "Testing Rails Applications":testing.html| |tmp/|Temporary files| -|vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you install it into your project) and plugins containing additional prepackaged functionality.| +|vendor/|A place for all third-party code. In a typical Rails application, this includes Ruby Gems, the Rails source code (if you optionally install it into your project) and plugins containing additional prepackaged functionality.| h4. Configuring a Database From 194a42e7aa7d1812257b14eabdd30c35f45bc8ed Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:24:44 -0700 Subject: [PATCH 17/36] Updated wording to read better --- railties/guides/source/getting_started.textile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index dfd27459b4..86fcb226d5 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -300,11 +300,12 @@ h4. Configuring a Database Just about every Rails application will interact with a database. The database to use is specified in a configuration file, +config/database.yml+. If you open this file in a new Rails application, you'll see a default database -configuration using SQLite3. The file contains sections for three different +configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default: -* The +development+ environment is used on your development computer as you interact manually with the application. -* The +test+ environment is used to run automated tests. +* The +development+ environment is used on your development/local computer as you interact +manually with the application. +* The +test+ environment is used when running automated tests. * The +production+ environment is used when you deploy your application for the world to use. h5. Configuring an SQLite3 Database From 4bf057b8661754948681a18cf17ff5676518d774 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:25:45 -0700 Subject: [PATCH 18/36] Move Tip up higher so users who are fine with SQLite can skip to the next section --- .../guides/source/getting_started.textile | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 86fcb226d5..63afc5898f 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -334,7 +334,17 @@ and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it. -h5. Configuring a MySQL Database +h5. Other database configuration options + +TIP: You don't have to update the database configurations manually. If you look at the +options of the application generator, you will see that one of the options +is named --database. This option allows you to choose an adapter from a +list of the most used relational databases. You can even run the generator +repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting + of the +config/database.yml+ file, your application will be configured for MySQL +instead of SQLite. + +h6. Configuring a MySQL Database If you choose to use MySQL instead of the shipped SQLite3 database, your +config/database.yml+ will look a little different. Here's the development @@ -355,7 +365,7 @@ If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the +development+ section as appropriate. -h5. Configuring a PostgreSQL Database +h6. Configuring a PostgreSQL Database If you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: @@ -370,9 +380,9 @@ development: password: -h5. Configuring an SQLite3 Database for JRuby Platform +h6. Configuring an SQLite3 Database for JRuby Platform -If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will +If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -381,9 +391,9 @@ development: database: db/development.sqlite3 -h5. Configuring a MySQL Database for JRuby Platform +h6. Configuring a MySQL Database for JRuby Platform -If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look +If you choose to use MySQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -394,9 +404,9 @@ development: password: -h5. Configuring a PostgreSQL Database for JRuby Platform +h6. Configuring a PostgreSQL Database for JRuby Platform -Finally if you choose to use PostgreSQL and are using JRuby, your +Finally if you choose to use PostgreSQL and using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -411,14 +421,6 @@ development: Change the username and password in the +development+ section as appropriate. -TIP: You don't have to update the database configurations manually. If you look at the -options of the application generator, you will see that one of the options -is named --database. This option allows you to choose an adapter from a -list of the most used relational databases. You can even run the generator -repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting - of the +config/database.yml+ file, your application will be configured for MySQL -instead of SQLite. - h4. Creating the Database Now that you have your database configured, it's time to have Rails create an From 703d5c2033665987c2fa6eff9f39095fb6c03061 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:26:23 -0700 Subject: [PATCH 19/36] Fix typo --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 63afc5898f..c40c21102c 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -494,7 +494,7 @@ Open this file in your text editor and edit it to contain a single line of code: h4. Setting the Application Home Page Now that we have made the controller and view, we need to tell Rails when we -want "Hello Rails" to show up. In our case, we want it to show up when we +want "Hello Rails!" to show up. In our case, we want it to show up when we navigate to the root URL of our site, "http://localhost:3000":http://localhost:3000, instead of the "Welcome Aboard" smoke test. From 434fbe454cb2367e74b757ba34b7035f7379ac8a Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:27:14 -0700 Subject: [PATCH 20/36] Update wording to flow better --- railties/guides/source/getting_started.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index c40c21102c..78cf01cdc0 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -515,8 +515,8 @@ file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. -Find the line beginning with +root :to+, uncomment it and change it like the -following: +Find the line beginning with +root :to+, uncomment it by removing the pound sign +at the beginning of the line. It should look something like the following: Blog::Application.routes.draw do @@ -544,7 +544,7 @@ resource in a single operation, scaffolding is the tool for the job. h3. Creating a Resource -In the case of the blog application, you can start by generating a scaffolded +In the case of the blog application, you can start by generating a scaffold for the Post resource: this will represent a single blog posting. To do this, enter this command in your terminal: From 094bb8e50c839be9f5ed93282ececeb4e3a15d76 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:28:09 -0700 Subject: [PATCH 21/36] Update order so they show up in the order they do in the scaffolding output --- railties/guides/source/getting_started.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 78cf01cdc0..d8e55eed60 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -558,21 +558,21 @@ folders, and edit config/routes.rb. Here's a quick overview of what it |_.File |_.Purpose| |db/migrate/20100207214725_create_posts.rb |Migration to create the posts table in your database (your name will include a different timestamp)| |app/models/post.rb |The Post model| -|test/fixtures/posts.yml |Dummy posts for use in testing| +|test/unit/post_test.rb |Unit testing harness for the posts model| +|test/fixtures/posts.yml |Sample posts for use in testing| +|config/routes.rb |Edited to include routing information for posts| |app/controllers/posts_controller.rb |The Posts controller| |app/views/posts/index.html.erb |A view to display an index of all posts | |app/views/posts/edit.html.erb |A view to edit an existing post| |app/views/posts/show.html.erb |A view to display a single post| |app/views/posts/new.html.erb |A view to create a new post| |app/views/posts/_form.html.erb |A partial to control the overall look and feel of the form used in edit and new views| -|app/helpers/posts_helper.rb |Helper functions to be used from the post views| -|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better| -|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller| -|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller| -|test/unit/post_test.rb |Unit testing harness for the posts model| |test/functional/posts_controller_test.rb |Functional testing harness for the posts controller| +|app/helpers/posts_helper.rb |Helper functions to be used from the post views| |test/unit/helpers/posts_helper_test.rb |Unit testing harness for the posts helper| -|config/routes.rb |Edited to include routing information for posts| +|app/assets/javascripts/posts.js.coffee |CoffeeScript for the posts controller| +|app/assets/stylesheets/posts.css.scss |Cascading style sheet for the posts controller| +|app/assets/stylesheets/scaffolds.css.scss |Cascading style sheet to make the scaffolded views look better| NOTE. While scaffolding will get you up and running quickly, the code it generates is unlikely to be a perfect fit for your application. You'll most From 06a8d16c8e0d87ab9a0dbba642aeb255f877cc8e Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:29:11 -0700 Subject: [PATCH 22/36] Update wording to be more explicit on what the timestamp fields track --- railties/guides/source/getting_started.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index d8e55eed60..01e0def226 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -609,12 +609,12 @@ class CreatePosts < ActiveRecord::Migration end -The above migration creates a method named +change+ which will be called when you -run this migration. The action defined in that method is also reversible, which +The above migration has one method named +change+ which will be called when you +run this migration. The action defined in this method is also reversible, which means Rails knows how to reverse the change made by this migration, in case you -want to reverse it at later date. By default, when you run this migration it -creates a +posts+ table with two string columns and a text column. It also -creates two timestamp fields to track record creation and updating. More +want to reverse it at later date. When you run this migration it will create a ++posts+ table with two string columns and a text column. It also creates two +timestamp fields to allow Rails to track post creation and update times. More information about Rails migrations can be found in the "Rails Database Migrations":migrations.html guide. From 1394c5447a8c27ab654556595468b7a0376c0cc9 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:31:07 -0700 Subject: [PATCH 23/36] Update wording to read better --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 01e0def226..d4bb55b5ba 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -634,7 +634,7 @@ table. == CreatePosts: migrated (0.0020s) =========================================== -NOTE. Because by default you're working in the development environment, this +NOTE. Because you're working in the development environment by default, this command will apply to the database defined in the +development+ section of your +config/database.yml+ file. If you would like to execute migrations in another environment, for instance in production, you must explicitly pass it when From fc8f0a85b5c6869aed3f8d05b15c6b014deb054f Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:31:33 -0700 Subject: [PATCH 24/36] Add link to AR Validations and Callbacks to further explain validations --- railties/guides/source/getting_started.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index d4bb55b5ba..1f1976393f 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -705,7 +705,8 @@ end These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their -format, and the existence of associated objects. +format, and the existence of associated objects. Validations are covered in detail +in "Active Record Validations and Callbacks":active_record_validations_callbacks.html#validations-overview h4. Using the Console From cb552f807e5bb2650791d17b01b6ac67c6023937 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:32:26 -0700 Subject: [PATCH 25/36] p.errors.full_messages is a little more human readable --- railties/guides/source/getting_started.textile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 1f1976393f..e88d0a7629 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -731,10 +731,8 @@ After the console loads, you can use it to work with your application's models: updated_at: nil> >> p.save => false ->> p.errors -=> #["can't be blank", - "is too short (minimum is 5 characters)"], - :name=>["can't be blank"] }> +>> p.errors.full_messages +=> ["Name can't be blank", "Title can't be blank", "Title is too short (minimum is 5 characters)"] This code shows creating a new +Post+ instance, attempting to save it and From 9b96f7414e7380266ed5ccf582f55f1e10ba877b Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:33:29 -0700 Subject: [PATCH 26/36] Be explicit about changing code --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index e88d0a7629..1d03698f4a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -742,8 +742,8 @@ inspecting the +errors+ of the post. When you're finished, type +exit+ and hit +return+ to exit the console. TIP: Unlike the development web server, the console does not automatically load -your code afresh for each line. If you make changes to your models while the -console is open, type +reload!+ at the console prompt to load them. +your code afresh for each line. If you make changes to your models (in your editor) +while the console is open, type +reload!+ at the console prompt to load them. h4. Listing All Posts From 3e3872b5985f0b360571b97cdc1b3203989d40fd Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:35:08 -0700 Subject: [PATCH 27/36] Make the guide more friendly - Changed Rails 3.0 to 3.0+ --- railties/guides/source/getting_started.textile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 1d03698f4a..bd929a6ae2 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -747,8 +747,9 @@ while the console is open, type +reload!+ at the console prompt to load them. h4. Listing All Posts -The easiest place to start looking at functionality is with the code that lists -all posts. Open the file +app/controllers/posts_controller.rb+ and look at the +Let's dive into the Rails code a little deeper to see how the application is +showing us the list of Posts. Open the file ++app/controllers/posts_controller.rb+ and look at the +index+ action: @@ -762,9 +763,9 @@ def index end -+Post.all+ calls the +Post+ model to return all of the posts currently in the -database. The result of this call is an array of posts that we store in an -instance variable called +@posts+. ++Post.all+ calls the all method on the +Post+ model, which returns all of +the posts currently in the database. The result of this call is an array +of Post records that we store in an instance variable called +@posts+. TIP: For more information on finding records with Active Record, see "Active Record Query Interface":active_record_querying.html. @@ -815,7 +816,7 @@ and links. A few things to note in the view: NOTE. In previous versions of Rails, you had to use +<%=h post.name %>+ so that any HTML would be escaped before being inserted into the page. In Rails -3.0, this is now the default. To get unescaped HTML, you now use +<%= raw +3.0+, this is now the default. To get unescaped HTML, you now use +<%= raw post.name %>+. TIP: For more details on the rendering process, see "Layouts and Rendering in @@ -829,9 +830,10 @@ Rails renders a view to the browser, it does so by putting the view's HTML into a layout's HTML. In previous versions of Rails, the +rails generate scaffold+ command would automatically create a controller specific layout, like +app/views/layouts/posts.html.erb+, for the posts controller. However this has -been changed in Rails 3.0. An application specific +layout+ is used for all the +been changed in Rails 3.0+. An application specific +layout+ is used for all the controllers and can be found in +app/views/layouts/application.html.erb+. Open -this layout in your editor and modify the +body+ tag: +this layout in your editor and modify the +body+ tag to include the style directive +below: From 5e83491e976c867c57892d1542dbbcf571bada41 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 01:40:28 -0700 Subject: [PATCH 28/36] Be explicit on where the show.html.erb is located --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index bd929a6ae2..8f48c52442 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1011,7 +1011,7 @@ end The +show+ action uses +Post.find+ to search for a single record in the database by its id value. After finding the record, Rails displays it by using -+show.html.erb+: ++app/views/posts/show.html.erb+:

<%= notice %>

From c0ee497436718ae6be50cfef5ee83473f1070fcd Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 03:12:13 -0700 Subject: [PATCH 29/36] Grammar change --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8f48c52442..d0ba07a82d 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1116,7 +1116,7 @@ the controller. h3. Adding a Second Model -Now that you've seen how a model built with scaffolding looks like, it's time to +Now that you've seen what a model built with scaffolding looks like, it's time to add a second model to the application. The second model will handle comments on blog posts. From 0774f22941f6846acd79a07d43cd417cd09a1998 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 03:13:58 -0700 Subject: [PATCH 30/36] Convert tables to table format --- .../guides/source/getting_started.textile | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index d0ba07a82d..f387dddce8 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1135,9 +1135,11 @@ $ rails generate model Comment commenter:string body:text post:references This command will generate four files: -* +app/models/comment.rb+ - The model. -* +db/migrate/20100207235629_create_comments.rb+ - The migration. -* +test/unit/comment_test.rb+ and +test/fixtures/comments.yml+ - The test harness. +|_.File |_.Purpose| +|db/migrate/20100207235629_create_comments.rb | Migration to create the comments table in your database (your name will include a different timestamp) | +| app/models/comment.rb | The Comment model | +| test/unit/comment_test.rb | Unit testing harness for the comments model | +| test/fixtures/comments.yml | Sample comments for use in testing | First, take a look at +comment.rb+: @@ -1258,13 +1260,14 @@ $ rails generate controller Comments This creates six files and one empty directory: -* +app/controllers/comments_controller.rb+ - The controller. -* +app/helpers/comments_helper.rb+ - A view helper file. -* +test/functional/comments_controller_test.rb+ - The functional tests for the controller. -* +test/unit/helpers/comments_helper_test.rb+ - The unit tests for the helper. -* +app/views/comments/+ - Views of the controller are stored here. -* +app/assets/stylesheets/comment.css.scss+ - Cascading style sheet for the controller. -* +app/assets/javascripts/comment.js.coffee+ - CoffeeScript for the controller. +|_.File/Directory |_.Purpose | +| app/controllers/comments_controller.rb | The Comments controller | +| app/views/comments/ | Views of the controller are stored here | +| test/functional/comments_controller_test.rb | The functional tests for the controller | +| app/helpers/comments_helper.rb | A view helper file | +| test/unit/helpers/comments_helper_test.rb | The unit tests for the helper | +| app/assets/javascripts/comment.js.coffee | CoffeeScript for the controller | +| app/assets/stylesheets/comment.css.scss | Cascading style sheet for the controller | Like with any blog, our readers will create their comments directly after reading the post, and once they have added their comment, will be sent back to From a3156ac0f2d57ca5a57c035530ff5b49f81716f3 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 03:15:22 -0700 Subject: [PATCH 31/36] Add output for add_index command --- railties/guides/source/getting_started.textile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index f387dddce8..8faacdd03e 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1186,8 +1186,10 @@ run against the current database, so in this case you will just see: == CreateComments: migrating ================================================= -- create_table(:comments) - -> 0.0017s -== CreateComments: migrated (0.0018s) ======================================== + -> 0.0008s +-- add_index(:comments, :post_id) + -> 0.0003s +== CreateComments: migrated (0.0012s) ======================================== h4. Associating Models From 50a9de514f8724b04d3681aa9ca228a8ca490909 Mon Sep 17 00:00:00 2001 From: Jason Noble Date: Sun, 13 Nov 2011 03:15:56 -0700 Subject: [PATCH 32/36] Update guide to use Ruby 1.9 hash syntax --- .../guides/source/getting_started.textile | 88 +++++++++---------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8faacdd03e..8f34e87e9a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -524,10 +524,10 @@ 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: "home#index" -The +root :to => "home#index"+ tells Rails to map the root action to the home +The +root to: "home#index"+ tells Rails to map the root action to the home controller's index action. Now if you navigate to "http://localhost:3000":http://localhost:3000 in your @@ -696,9 +696,9 @@ Open the +app/models/post.rb+ file and edit it: class Post < ActiveRecord::Base - validates :name, :presence => true - validates :title, :presence => true, - :length => { :minimum => 5 } + validates :name, presence: true + validates :title, presence: true, + length: { minimum: 5 } end @@ -725,7 +725,7 @@ open a console that will roll back any changes you make by using rails conso After the console loads, you can use it to work with your application's models: ->> p = Post.new(:content => "A new post") +>> p = Post.new(content: "A new post") => # @@ -758,11 +758,15 @@ def index respond_to do |format| format.html # index.html.erb - format.json { render :json => @posts } + format.json { render json: @posts } end end +TIP: This Guide was written using Ruby 1.9.2. If you are using Ruby 1.8.7, some of +the syntax may look slightly different. For example, the hash syntax changed from +render :json => @posts (1.8.7) to render json: @posts (1.9.2). + +Post.all+ calls the all method on the +Post+ model, which returns all of the posts currently in the database. The result of this call is an array of Post records that we store in an instance variable called +@posts+. @@ -797,8 +801,7 @@ Here's +app/views/posts/index.html.erb+: <%= post.content %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, :confirm => 'Are you sure?', - :method => :delete %> + <%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %> <% end %> @@ -866,7 +869,7 @@ def new respond_to do |format| format.html # new.html.erb - format.json { render :json => @post } + format.json { render json: @post } end end @@ -958,14 +961,11 @@ def create respond_to do |format| if @post.save - format.html { redirect_to(@post, - :notice => 'Post was successfully created.') } - format.json { render :json => @post, - :status => :created, :location => @post } + format.html { redirect_to @post, notice: 'Post was successfully created.' } + format.json { render json: @post, status: :created, location: @post } else - format.html { render :action => "new" } - format.json { render :json => @post.errors, - :status => :unprocessable_entity } + format.html { render action: "new" } + format.json { render json: @post.errors, status: :unprocessable_entity } end end end @@ -1003,8 +1003,8 @@ def show @post = Post.find(params[:id]) respond_to do |format| - format.html # show.html.erb - format.json { render :json => @post } + format.html # show.html.erb + format.json { render json: @post } end end @@ -1073,13 +1073,11 @@ def update respond_to do |format| if @post.update_attributes(params[:post]) - format.html { redirect_to(@post, - :notice => 'Post was successfully updated.') } - format.json { render :json => {}, :status => :ok } + format.html { redirect_to @post, notice: 'Post was successfully updated.' } + format.json { head :ok } else - format.html { render :action => "edit" } - format.json { render :json => @post.errors, - :status => :unprocessable_entity } + format.html { render action: "edit" } + format.json { render json: @post.errors, status: :unprocessable_entity } end end end @@ -1215,9 +1213,9 @@ You'll need to edit the +post.rb+ file to add the other side of the association: class Post < ActiveRecord::Base - validates :name, :presence => true - validates :title, :presence => true, - :length => { :minimum => 5 } + validates :name, presence: true + validates :title, presence: true, + length: { :minimum: 5 } has_many :comments end @@ -1559,8 +1557,8 @@ So first, let's add the delete link in the

<%= link_to 'Destroy Comment', [comment.post, comment], - :confirm => 'Are you sure?', - :method => :delete %> + confirm: 'Are you sure?', + method: :delete %>

@@ -1602,10 +1600,10 @@ model, +app/models/post.rb+, as follows: class Post < ActiveRecord::Base - validates :name, :presence => true - validates :title, :presence => true, - :length => { :minimum => 5 } - has_many :comments, :dependent => :destroy + validates :name, presence: true + validates :title, presence: true, + length: {minimum: 5} + has_many :comments, dependent: :destroy end @@ -1629,7 +1627,7 @@ action, except for +index+ and +show+, so we write that: class PostsController < ApplicationController - http_basic_authenticate_with :name => "dhh", :password => "secret", :except => [:index, :show] + http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show] # GET /posts # GET /posts.json @@ -1645,7 +1643,7 @@ We also only want to allow authenticated users to delete comments, so in the class CommentsController < ApplicationController - http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy + http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy def create @post = Post.find(params[:post_id]) @@ -1683,15 +1681,14 @@ edit tags via posts: class Post < ActiveRecord::Base - validates :name, :presence => true - validates :title, :presence => true, - :length => { :minimum => 5 } - - has_many :comments, :dependent => :destroy + validates :name, presence: true + validates :title, presence: true, + length: {minimum: 5} + has_many :comments, dependent: :destroy has_many :tags - accepts_nested_attributes_for :tags, :allow_destroy => :true, - :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } + accepts_nested_attributes_for :tags, allow_destroy: :true, + reject_if: proc { |attrs| attrs.all? { |k, v| v.blank? } } end @@ -1729,8 +1726,9 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag: <%= post_form.text_area :content %>

Tags

- <%= render :partial => 'tags/form', - :locals => {:form => post_form} %> + <%= render partial: 'tags/form', + locals: {form: post_form} %> +
<%= post_form.submit %>
From e1099eb4fdb64b82485843a569ecd5006aa3dad8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 13 Nov 2011 21:50:18 +0530 Subject: [PATCH 33/36] Revert "Update guide to use Ruby 1.9 hash syntax" This reverts commit 50a9de514f8724b04d3681aa9ca228a8ca490909. Reason: Let's keep the guides at 1.8 syntax --- .../guides/source/getting_started.textile | 88 ++++++++++--------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8f34e87e9a..8faacdd03e 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -524,10 +524,10 @@ 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 => "home#index"
-The +root to: "home#index"+ tells Rails to map the root action to the home +The +root :to => "home#index"+ tells Rails to map the root action to the home controller's index action. Now if you navigate to "http://localhost:3000":http://localhost:3000 in your @@ -696,9 +696,9 @@ Open the +app/models/post.rb+ file and edit it: class Post < ActiveRecord::Base - validates :name, presence: true - validates :title, presence: true, - length: { minimum: 5 } + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } end @@ -725,7 +725,7 @@ open a console that will roll back any changes you make by using rails conso After the console loads, you can use it to work with your application's models: ->> p = Post.new(content: "A new post") +>> p = Post.new(:content => "A new post") => # @@ -758,15 +758,11 @@ def index respond_to do |format| format.html # index.html.erb - format.json { render json: @posts } + format.json { render :json => @posts } end end
-TIP: This Guide was written using Ruby 1.9.2. If you are using Ruby 1.8.7, some of -the syntax may look slightly different. For example, the hash syntax changed from -render :json => @posts (1.8.7) to render json: @posts (1.9.2). - +Post.all+ calls the all method on the +Post+ model, which returns all of the posts currently in the database. The result of this call is an array of Post records that we store in an instance variable called +@posts+. @@ -801,7 +797,8 @@ Here's +app/views/posts/index.html.erb+: <%= post.content %> <%= link_to 'Show', post %> <%= link_to 'Edit', edit_post_path(post) %> - <%= link_to 'Destroy', post, confirm: 'Are you sure?', method: :delete %> + <%= link_to 'Destroy', post, :confirm => 'Are you sure?', + :method => :delete %> <% end %> @@ -869,7 +866,7 @@ def new respond_to do |format| format.html # new.html.erb - format.json { render json: @post } + format.json { render :json => @post } end end @@ -961,11 +958,14 @@ def create respond_to do |format| if @post.save - format.html { redirect_to @post, notice: 'Post was successfully created.' } - format.json { render json: @post, status: :created, location: @post } + format.html { redirect_to(@post, + :notice => 'Post was successfully created.') } + format.json { render :json => @post, + :status => :created, :location => @post } else - format.html { render action: "new" } - format.json { render json: @post.errors, status: :unprocessable_entity } + format.html { render :action => "new" } + format.json { render :json => @post.errors, + :status => :unprocessable_entity } end end end @@ -1003,8 +1003,8 @@ def show @post = Post.find(params[:id]) respond_to do |format| - format.html # show.html.erb - format.json { render json: @post } + format.html # show.html.erb + format.json { render :json => @post } end end @@ -1073,11 +1073,13 @@ def update respond_to do |format| if @post.update_attributes(params[:post]) - format.html { redirect_to @post, notice: 'Post was successfully updated.' } - format.json { head :ok } + format.html { redirect_to(@post, + :notice => 'Post was successfully updated.') } + format.json { render :json => {}, :status => :ok } else - format.html { render action: "edit" } - format.json { render json: @post.errors, status: :unprocessable_entity } + format.html { render :action => "edit" } + format.json { render :json => @post.errors, + :status => :unprocessable_entity } end end end @@ -1213,9 +1215,9 @@ You'll need to edit the +post.rb+ file to add the other side of the association: class Post < ActiveRecord::Base - validates :name, presence: true - validates :title, presence: true, - length: { :minimum: 5 } + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } has_many :comments end @@ -1557,8 +1559,8 @@ So first, let's add the delete link in the

<%= link_to 'Destroy Comment', [comment.post, comment], - confirm: 'Are you sure?', - method: :delete %> + :confirm => 'Are you sure?', + :method => :delete %>

@@ -1600,10 +1602,10 @@ model, +app/models/post.rb+, as follows: class Post < ActiveRecord::Base - validates :name, presence: true - validates :title, presence: true, - length: {minimum: 5} - has_many :comments, dependent: :destroy + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } + has_many :comments, :dependent => :destroy end @@ -1627,7 +1629,7 @@ action, except for +index+ and +show+, so we write that: class PostsController < ApplicationController - http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show] + http_basic_authenticate_with :name => "dhh", :password => "secret", :except => [:index, :show] # GET /posts # GET /posts.json @@ -1643,7 +1645,7 @@ We also only want to allow authenticated users to delete comments, so in the class CommentsController < ApplicationController - http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy + http_basic_authenticate_with :name => "dhh", :password => "secret", :only => :destroy def create @post = Post.find(params[:post_id]) @@ -1681,14 +1683,15 @@ edit tags via posts: class Post < ActiveRecord::Base - validates :name, presence: true - validates :title, presence: true, - length: {minimum: 5} - has_many :comments, dependent: :destroy + validates :name, :presence => true + validates :title, :presence => true, + :length => { :minimum => 5 } + + has_many :comments, :dependent => :destroy has_many :tags - accepts_nested_attributes_for :tags, allow_destroy: :true, - reject_if: proc { |attrs| attrs.all? { |k, v| v.blank? } } + accepts_nested_attributes_for :tags, :allow_destroy => :true, + :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } end @@ -1726,9 +1729,8 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag: <%= post_form.text_area :content %>

Tags

- <%= render partial: 'tags/form', - locals: {form: post_form} %> - + <%= render :partial => 'tags/form', + :locals => {:form => post_form} %>
<%= post_form.submit %>
From c8c08bd000c00817d2f17f560f392965fd82229b Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 13 Nov 2011 21:57:39 +0530 Subject: [PATCH 34/36] Revert "Use rails help new instead of rails new -h" This reverts commit 6ac65c92029d3eefd101f9458d86bae0314cd14c. --- railties/guides/source/getting_started.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8faacdd03e..98e7c93dc7 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -263,7 +263,8 @@ $ rails new blog This will create a Rails application called Blog in a directory called blog. TIP: You can see all of the switches that the Rails application builder accepts -by running rails help new. +by running +rails new -h. After you create the blog application, switch to its folder to continue work directly in that application: From af51409de433f14d251f7f229a2f651d3ddf7b1c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 13 Nov 2011 22:07:54 +0530 Subject: [PATCH 35/36] Revert "Move Tip up higher so users who are fine with SQLite can skip to the next section" This reverts commit 4bf057b8661754948681a18cf17ff5676518d774. Reason: Prefer to keep the configuration of all databases at the same level --- .../guides/source/getting_started.textile | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 98e7c93dc7..9e774ff298 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -335,17 +335,7 @@ and PostgreSQL "out of the box", and has plugins for many database systems. If you are using a database in a production environment Rails most likely has an adapter for it. -h5. Other database configuration options - -TIP: You don't have to update the database configurations manually. If you look at the -options of the application generator, you will see that one of the options -is named --database. This option allows you to choose an adapter from a -list of the most used relational databases. You can even run the generator -repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting - of the +config/database.yml+ file, your application will be configured for MySQL -instead of SQLite. - -h6. Configuring a MySQL Database +h5. Configuring a MySQL Database If you choose to use MySQL instead of the shipped SQLite3 database, your +config/database.yml+ will look a little different. Here's the development @@ -366,7 +356,7 @@ If your development computer's MySQL installation includes a root user with an empty password, this configuration should work for you. Otherwise, change the username and password in the +development+ section as appropriate. -h6. Configuring a PostgreSQL Database +h5. Configuring a PostgreSQL Database If you choose to use PostgreSQL, your +config/database.yml+ will be customized to use PostgreSQL databases: @@ -381,9 +371,9 @@ development: password: -h6. Configuring an SQLite3 Database for JRuby Platform +h5. Configuring an SQLite3 Database for JRuby Platform -If you choose to use SQLite3 and using JRuby, your +config/database.yml+ will +If you choose to use SQLite3 and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -392,9 +382,9 @@ development: database: db/development.sqlite3 -h6. Configuring a MySQL Database for JRuby Platform +h5. Configuring a MySQL Database for JRuby Platform -If you choose to use MySQL and using JRuby, your +config/database.yml+ will look +If you choose to use MySQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -405,9 +395,9 @@ development: password: -h6. Configuring a PostgreSQL Database for JRuby Platform +h5. Configuring a PostgreSQL Database for JRuby Platform -Finally if you choose to use PostgreSQL and using JRuby, your +Finally if you choose to use PostgreSQL and are using JRuby, your +config/database.yml+ will look a little different. Here's the development section: @@ -422,6 +412,14 @@ development: Change the username and password in the +development+ section as appropriate. +TIP: You don't have to update the database configurations manually. If you look at the +options of the application generator, you will see that one of the options +is named --database. This option allows you to choose an adapter from a +list of the most used relational databases. You can even run the generator +repeatedly: cd .. && rails new blog --database=mysql. When you confirm the overwriting + of the +config/database.yml+ file, your application will be configured for MySQL +instead of SQLite. + h4. Creating the Database Now that you have your database configured, it's time to have Rails create an From 30122307a1fe6645d6a75dedceca40a440f2f969 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sun, 13 Nov 2011 22:27:44 +0530 Subject: [PATCH 36/36] copy edits in getting started guide --- .../guides/source/getting_started.textile | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 9e774ff298..5f370615ca 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -221,8 +221,7 @@ h3. Creating a New Rails Project The best way to use this guide is to follow each step as it happens, no code or step needed to make this example application has been left out, so you can -literally follow along step by step. If you need to see the completed code, you -can download it from "Getting Started Code":https://github.com/mikel/getting-started-code. +literally follow along step by step. You can get the complete code "here":https://github.com/lifo/docrails/tree/master/railties/guides/code/getting_started. By following along with this guide, you'll create a Rails project called blog, a (very) simple weblog. Before you can start building the application, you need to @@ -246,7 +245,7 @@ To verify that you have everything installed correctly, you should be able to ru the following: -# rails --version +$ rails --version If it says something like "Rails 3.1.1" you are ready to continue. @@ -273,7 +272,7 @@ directly in that application: $ cd blog -The 'rails new blog' command we ran above created a folder in your working directory +The 'rails new blog' command we ran above created a folder in your working directory called blog. The blog folder has a number of auto-generated folders that make up the structure of a Rails application. Most of the work in this tutorial will happen in the app/ folder, but here's a basic @@ -304,7 +303,7 @@ this file in a new Rails application, you'll see a default database configured to use SQLite3. The file contains sections for three different environments in which Rails can run by default: -* The +development+ environment is used on your development/local computer as you interact +* The +development+ environment is used on your development/local computer as you interact manually with the application. * The +test+ environment is used when running automated tests. * The +production+ environment is used when you deploy your application for the world to use. @@ -514,8 +513,7 @@ file_ which holds entries in a special DSL (domain-specific language) that tells Rails how to connect incoming requests to controllers and actions. This file contains many sample routes on commented lines, and one of them actually shows you how to connect the root of your site to a specific controller and action. -Find the line beginning with +root :to+, uncomment it by removing the pound sign -at the beginning of the line. It should look something like the following: +Find the line beginning with +root :to+ and uncomment it. It should look something like the following: Blog::Application.routes.draw do @@ -608,11 +606,11 @@ class CreatePosts < ActiveRecord::Migration end -The above migration has one method named +change+ which will be called when you +The above migration creates a method named +change+ which will be called when you run this migration. The action defined in this method is also reversible, which means Rails knows how to reverse the change made by this migration, in case you -want to reverse it at later date. When you run this migration it will create a -+posts+ table with two string columns and a text column. It also creates two +want to reverse it later. When you run this migration it will create a ++posts+ table with two string columns and a text column. It also creates two timestamp fields to allow Rails to track post creation and update times. More information about Rails migrations can be found in the "Rails Database Migrations":migrations.html guide. @@ -704,7 +702,7 @@ end These changes will ensure that all posts have a name and a title, and that the title is at least five characters long. Rails can validate a variety of conditions in a model, including the presence or uniqueness of columns, their -format, and the existence of associated objects. Validations are covered in detail +format, and the existence of associated objects. Validations are covered in detail in "Active Record Validations and Callbacks":active_record_validations_callbacks.html#validations-overview h4. Using the Console @@ -747,7 +745,7 @@ while the console is open, type +reload!+ at the console prompt to load them. h4. Listing All Posts Let's dive into the Rails code a little deeper to see how the application is -showing us the list of Posts. Open the file +showing us the list of Posts. Open the file +app/controllers/posts_controller.rb+ and look at the +index+ action: @@ -762,9 +760,8 @@ def index end
-+Post.all+ calls the all method on the +Post+ model, which returns all of -the posts currently in the database. The result of this call is an array -of Post records that we store in an instance variable called +@posts+. ++Post.all+ returns all of the posts currently in the database as an array +of +Post+ records that we store in an instance variable called +@posts+. TIP: For more information on finding records with Active Record, see "Active Record Query Interface":active_record_querying.html.