From 078177a3dc0b0893a1197f104c91f1df3902f939 Mon Sep 17 00:00:00 2001 From: eparreno Date: Sat, 17 Apr 2010 23:45:08 +0200 Subject: fix testing guide: fonts and code format --- railties/guides/source/testing.textile | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index c4f7ff8e92..206ed6e75c 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -108,7 +108,7 @@ tag is considered Ruby code. When this fixture is loaded, the +size+ attribute o h5. Fixtures in Action -Rails by default automatically loads all fixtures from the 'test/fixtures' folder for your unit and functional test. Loading involves three steps: +Rails by default automatically loads all fixtures from the +test/fixtures+ folder for your unit and functional test. Loading involves three steps: * Remove any existing data from the table corresponding to the fixture * Load the fixture data into the table @@ -142,7 +142,7 @@ In Rails, unit tests are what you write to test your models. For this guide we will be using Rails _scaffolding_. It will create the model, a migration, controller and views for the new resource in a single operation. It will also create a full test suite following Rails best practices. I will be using examples from this generated code and would be supplementing it with additional examples where necessary. -NOTE: For more information on Rails _scaffolding_, refer to "Getting Started with Rails":getting_started.html +NOTE: For more information on Rails scaffolding, refer to "Getting Started with Rails":getting_started.html When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: @@ -221,9 +221,9 @@ $ rake db:migrate $ rake db:test:load -Above +rake db:migrate+ runs any pending migrations on the _development_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current db/schema.rb. On subsequent attempts it is a good to first run +db:test:prepare+ as it first checks for pending migrations and warns you appropriately. +Above +rake db:migrate+ runs any pending migrations on the _development_ environment and updates +db/schema.rb+. +rake db:test:load+ recreates the test database from the current +db/schema.rb+. On subsequent attempts it is a good to first run +db:test:prepare+ as it first checks for pending migrations and warns you appropriately. -NOTE: +db:test:prepare+ will fail with an error if db/schema.rb doesn't exists. +NOTE: +db:test:prepare+ will fail with an error if +db/schema.rb+ doesn't exists. h5. Rake Tasks for Preparing your Application for Testing @@ -256,7 +256,7 @@ This will run all the test methods from the test case. You can also run a particular test method from the test case by using the +-n+ switch with the +test method name+. -
+
 $ ruby unit/post_test.rb -n test_truth
 
 Loaded suite unit/post_test
@@ -265,7 +265,7 @@ Started
 Finished in 0.023513 seconds.
 
 1 tests, 1 assertions, 0 failures, 0 errors
-
+ The +.+ (dot) above indicates a passing test. When a test fails you see an +F+; when a test throws an error you see an +E+ in its place. The last line of the output is the summary. @@ -280,7 +280,7 @@ end Let us run this newly added test. -
+
 $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
 Loaded suite -e
 Started
@@ -292,7 +292,7 @@ test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
  is not true.
 
 1 tests, 1 assertions, 1 failures, 0 errors
-
+ In the output, +F+ denotes a failure. You can see the corresponding trace shown under +1)+ along with the name of the failing test. The next few lines contain the stack trace followed by a message which mentions the actual value and the expected value by the assertion. The default assertion messages provide just enough information to help pinpoint the error. To make the assertion failure message more readable every assertion provides an optional message parameter, as shown here: @@ -305,12 +305,12 @@ end Running this test shows the friendlier assertion message: -
+
   1) Failure:
 test_should_not_save_post_without_title(PostTest) [/test/unit/post_test.rb:6]:
 Saved the post without a title.
  is not true.
-
+ Now to get this test to pass we can add a model level validation for the _title_ field. @@ -322,7 +322,7 @@ end Now the test should pass. Let us verify by running the test again: -
+
 $ ruby unit/post_test.rb -n test_should_not_save_post_without_title
 Loaded suite unit/post_test
 Started
@@ -330,7 +330,7 @@ Started
 Finished in 0.193608 seconds.
 
 1 tests, 1 assertions, 0 failures, 0 errors
-
+ Now if you noticed we first wrote a test which fails for a desired functionality, then we wrote some code which adds the functionality and finally we ensured that our test passes. This approach to software development is referred to as _Test-Driven Development_ (TDD). @@ -348,7 +348,7 @@ end Now you can see even more output in the console from running the tests: -
+
 $ ruby unit/post_test.rb -n test_should_report_error
 Loaded suite -e
 Started
@@ -361,7 +361,7 @@ NameError: undefined local variable or method `some_undefined_variable' for #
+
 
 Notice the 'E' in the output. It denotes a test with error.
 
@@ -446,7 +446,7 @@ test "should get index" do
 end
 
 
-In the +test_should_get_index+ test, Rails simulates a request on the action called index, making sure the request was successful and also ensuring that it assigns a valid +posts+ instance variable.
+In the +test_should_get_index+ test, Rails simulates a request on the action called +index+, making sure the request was successful and also ensuring that it assigns a valid +posts+ instance variable.
 
 The +get+ method kicks off the web request and populates the results into the response. It accepts 4 arguments:
 
-- 
cgit v1.2.3


From ea3fa4e7ffbdb771e06545f22f71bc4e7f6a334c Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Sat, 17 Apr 2010 16:43:31 +0200
Subject: AS guide: AS no longer extends Pathname

---
 railties/guides/source/active_support_core_extensions.textile | 4 ----
 1 file changed, 4 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 398d2b2392..32738fe070 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -2662,10 +2662,6 @@ h3. Extensions to +Process+
 
 ...
 
-h3. Extensions to +Pathname+
-
-...
-
 h3. Extensions to +File+
 
 h4. +atomic_write+
-- 
cgit v1.2.3


From 2bae20138a4e3cb37ce26e396a4b14455a947ba2 Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Mon, 19 Apr 2010 02:15:04 -0700
Subject: Replaced ',' with 'or' to make it read better.

---
 railties/guides/source/getting_started.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index cbace177f9..58f2eaf178 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -87,7 +87,7 @@ Action View manages the views of your Rails application. It can create both HTML
 
 h5. Action Dispatch
 
-Action Dispatch handles routing of web requests and dispatches them as you want, either to your application, any other Rack application.
+Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application.
 
 h5. Action Mailer
 
-- 
cgit v1.2.3


From 3948ba89e143eeebb8a2a9bd5f370abb66a47377 Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Mon, 19 Apr 2010 02:54:50 -0700
Subject: Fixed wrong purpose of _form.html.erb

---
 railties/guides/source/getting_started.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 58f2eaf178..6cc989d156 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -363,7 +363,7 @@ The scaffold generator will build 15 files in your application, along with some
 |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 view to control the overall look and feel of the other posts views|
+|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/views/layouts/posts.html.erb             |A view to control the overall look and feel of the other posts views|
 |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 posts views|
-- 
cgit v1.2.3


From a870c4928cac8bf14ddbda487108bce45bed0fa2 Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Mon, 19 Apr 2010 03:12:52 -0700
Subject: Cleaned up the table of files created by scaffolding a Post.

---
 railties/guides/source/getting_started.textile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 6cc989d156..09190f5800 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -356,7 +356,6 @@ The scaffold generator will build 15 files in your application, along with some
 |_.File                                       |_.Purpose|
 |db/migrate/20100207214725_create_posts.rb.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/unit/post_test.rb                       |Unit testing harness for the posts model|
 |test/fixtures/posts.yml                      |Dummy posts for use in testing|
 |app/controllers/posts_controller.rb          |The Posts controller|
 |app/views/posts/index.html.erb               |A view to display an index of all posts |
@@ -364,11 +363,12 @@ The scaffold generator will build 15 files in your application, along with some
 |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/views/layouts/posts.html.erb             |A view to control the overall look and feel of the other posts views|
+|app/views/layouts/posts.html.erb             |A view to control the overall look and feel of the other post views|
+|app/helpers/posts_helper.rb                  |Helper functions to be used from the post views|
+|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 posts views|
-|config/routes.rb                             |Edited to include routing information for posts|
 |test/unit/helpers/posts_helper_test.rb       |Unit testing harness for the posts helper|
+|config/routes.rb                             |Edited to include routing information for posts|
 |public/stylesheets/scaffold.css              |Cascading style sheet to make the scaffolded views look better|
 
 h4. Running a Migration
-- 
cgit v1.2.3


From e00c72c9718e518eb99058781f6ee71fa46b38fe Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow 
Date: Mon, 19 Apr 2010 18:29:18 +0800
Subject: Rails on Rack Rails guide: indicate that Metal pieces now require an
 "X-Cascade" header with a value of "pass" to continue the Metal chain
 execution instead of a HTTP 404 response. Also removed reference to old code.

---
 railties/guides/source/rails_on_rack.textile | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index d0d86e99f2..512be43668 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -247,7 +247,7 @@ class Poller
     if env["PATH_INFO"] =~ /^\/poller/
       [200, {"Content-Type" => "text/html"}, ["Hello, World!"]]
     else
-      [404, {"Content-Type" => "text/html"}, ["Not Found"]]
+      [404, {"Content-Type" => "text/html", "X-Cascade" => "pass"}, ["Not Found"]]
     end
   end
 end
@@ -257,23 +257,13 @@ Metal applications within +app/metal+ folders in plugins will also be discovered
 
 Metal applications are an optimization. You should make sure to "understand the related performance implications":http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal before using it.
 
-h4. Execution Order
-
-All Metal Applications are executed by +Rails::Rack::Metal+ middleware, which is a part of the +ActionController::MiddlewareStack+ chain.
+WARNING: To continue the Metal chain execution, return an +X-Cascade+ HTTP header with a value of +pass+.
 
-Here's the primary method responsible for running the Metal applications:
+h4. Execution Order
 
-
-def call(env)
-  @metals.keys.each do |app|
-    result = app.call(env)
-    return result unless result[0].to_i == 404
-  end
-  @app.call(env)
-end
-
+All Metal Applications are executed in alphabetical order of their filenames, so +aaa.rb+ will come before +bbb.rb+ in the metal chain.
 
-In the code above, +@metals+ is an ordered hash of metal applications. Due to the default alphabetical ordering, +aaa.rb+ will come before +bbb.rb+ in the metal chain.
+You can override the default ordering in your environment. Simply add a line like the following to +config/application.rb+
 
 It is, however, possible to override the default ordering in your environment. Simply add a line like the following to +config/environment.rb+
 
@@ -283,8 +273,6 @@ config.metals = ["Bbb", "Aaa"]
 
 Each string in the array should be the name of your metal class. If you do this then be warned that any metal applications not listed will not be loaded.
 
-WARNING: Metal applications cannot return the HTTP Status +404+ to a client, as it is used for continuing the Metal chain execution. Please use normal Rails controllers or a custom middleware if returning +404+ is a requirement.
-
 h3. Resources
 
 h4. Learning Rack
-- 
cgit v1.2.3


From fdf032d673e9952ffe59f60423f53310499e5029 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino 
Date: Mon, 19 Apr 2010 12:30:58 -0300
Subject: rails about is now rake about

---
 railties/guides/source/command_line.textile | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index ebae320ebc..873691d13c 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -320,21 +320,20 @@ h4. +about+
 Check it: Version numbers for Ruby, RubyGems, Rails, the Rails subcomponents, your application's folder, the current Rails environment name, your app's database adapter, and schema version! +about+ is useful when you need to ask for help, check if a security patch might affect you, or when you need some stats for an existing Rails installation.
 
 
-$ rails about
+$ rake about
 About your application's environment
-Ruby version              1.8.6 (i486-linux)
-RubyGems version          1.3.1
-Rails version             2.2.0
-Active Record version     2.2.0
-Action Pack version       2.2.0
-Active Resource version   2.2.0
-Action Mailer version     2.2.0
-Active Support version    2.2.0
-Edge Rails revision       unknown
-Application root          /home/commandsapp
+Ruby version              1.8.7 (x86_64-linux)
+RubyGems version          1.3.6
+Rack version              1.1
+Rails version             3.0.0
+Active Record version     3.0.0
+Action Pack version       3.0.0
+Active Resource version   3.0.0
+Action Mailer version     3.0.0
+Active Support version    3.0.0
+Middleware                ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
+Application root          /home/myapp
 Environment               development
-Database adapter          sqlite3
-Database schema version   20081217073400
 
 
 h3. The Rails Advanced Command Line
-- 
cgit v1.2.3


From fa2e70b6e00c72b77b574d291be79caee1a045f0 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino 
Date: Mon, 19 Apr 2010 12:34:42 -0300
Subject: let's talk about the same path

---
 railties/guides/source/command_line.textile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 873691d13c..2a42bcf211 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -237,7 +237,7 @@ The migration requires that we *migrate*, that is, run some Ruby code (living in
 
 
 $ rake db:migrate
-(in /Users/mikel/rails_programs/commandsapp)
+(in /home/foobar/commandsapp)
 ==  CreateHighScores: migrating ===============================================
 -- create_table(:high_scores)
    -> 0.0026s
@@ -332,7 +332,7 @@ Active Resource version   3.0.0
 Action Mailer version     3.0.0
 Active Support version    3.0.0
 Middleware                ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
-Application root          /home/myapp
+Application root          /home/foobar/commandsapp
 Environment               development
 
 
@@ -525,7 +525,7 @@ You can get a list of Rake tasks available to you, which will often depend on yo
 
 
  rake --tasks
-(in /home/developer/commandsapp)
+(in /home/foobar/commandsapp)
 rake db:abort_if_pending_migrations       # Raises an error if there are pending migrations
 rake db:charset                           # Retrieves the charset for the current environment's database
 rake db:collation                         # Retrieves the collation for the current environment's database
-- 
cgit v1.2.3


From e35dcd64bc8604b3de64198226b572433642849b Mon Sep 17 00:00:00 2001
From: Santiago Pastorino 
Date: Mon, 19 Apr 2010 12:35:59 -0300
Subject: Rails 3.0.0 version bootup messages

---
 railties/guides/source/command_line.textile | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile
index 2a42bcf211..ab024d7fc3 100644
--- a/railties/guides/source/command_line.textile
+++ b/railties/guides/source/command_line.textile
@@ -64,12 +64,13 @@ Without any prodding of any kind, +rails server+ will run our new shiny Rails ap
 
 $ cd commandsapp
 $ rails server
-=> Booting WEBrick...
-=> Rails 2.2.0 application started on http://0.0.0.0:3000
-=> Ctrl-C to shutdown server; call with --help for options
-[2008-11-04 10:11:38] INFO  WEBrick 1.3.1
-[2008-11-04 10:11:38] INFO  ruby 1.8.5 (2006-12-04) [i486-linux]
-[2008-11-04 10:11:38] INFO  WEBrick::HTTPServer#start: pid=18994 port=3000
+=> Booting WEBrick
+=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
+=> Call with -d to detach
+=> Ctrl-C to shutdown server
+[2010-04-18 03:20:33] INFO  WEBrick 1.3.1
+[2010-04-18 03:20:33] INFO  ruby 1.8.7 (2010-01-10) [x86_64-linux]
+[2010-04-18 03:20:33] INFO  WEBrick::HTTPServer#start: pid=26086 port=3000
 
 
 With just three commands we whipped up a Rails server listening on port 3000. Go to your browser and open "http://localhost:3000":http://localhost:3000, you will see a basic rails app running.
-- 
cgit v1.2.3


From 86a43ed8a1123b5fa039651781e05e077df8c637 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino 
Date: Mon, 19 Apr 2010 13:50:59 -0300
Subject: Changed versions to ruby 1.8.7 and Rails 3.0.0

---
 railties/guides/source/performance_testing.textile | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index f74b68b0ef..c02fabc0b2 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -246,16 +246,16 @@ Sample output of +BrowsingTest#test_homepage_wall_time.csv+:
 
 
 measurement,created_at,app,rails,ruby,platform
-0.00738224999999992,2009-01-08T03:40:29Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
-0.00755874999999984,2009-01-08T03:46:18Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
-0.00762099999999993,2009-01-08T03:49:25Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
-0.00603075000000008,2009-01-08T04:03:29Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
-0.00619899999999995,2009-01-08T04:03:53Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
-0.00755449999999991,2009-01-08T04:04:55Z,,2.3.0.master.0744148,ruby-1.8.6.110,i686-darwin9.0.0
-0.00595999999999997,2009-01-08T04:05:06Z,,2.3.0.master.0744148,ruby-1.8.6.111,i686-darwin9.1.0
-0.00740450000000004,2009-01-09T03:54:47Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0
-0.00603150000000008,2009-01-09T03:54:57Z,,2.3.0.master.859e150,ruby-1.8.6.111,i686-darwin9.1.0
-0.00771250000000012,2009-01-09T15:46:03Z,,2.3.0.master.859e150,ruby-1.8.6.110,i686-darwin9.0.0
+0.00738224999999992,2009-01-08T03:40:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00755874999999984,2009-01-08T03:46:18Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00762099999999993,2009-01-08T03:49:25Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00603075000000008,2009-01-08T04:03:29Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00619899999999995,2009-01-08T04:03:53Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00755449999999991,2009-01-08T04:04:55Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00595999999999997,2009-01-08T04:05:06Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00740450000000004,2009-01-09T03:54:47Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00603150000000008,2009-01-09T03:54:57Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
+0.00771250000000012,2009-01-09T15:46:03Z,,3.0.0,ruby-1.8.7.249,x86_64-linux
 
 
 h5(#output-profiling). Profiling
-- 
cgit v1.2.3


From a9d05787116db2597237b34a048abe62d252b304 Mon Sep 17 00:00:00 2001
From: Mikel Lindsaar 
Date: Tue, 20 Apr 2010 14:45:30 +1000
Subject: Adding auto encoding of headers and bodies to the guide for
 ActionMailer

---
 railties/guides/source/action_mailer_basics.textile | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 79cb86ee97..794dc74900 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -148,6 +148,14 @@ NOTE: In previous versions of Rails, you would call +deliver_welcome_email+ or +
 
 WARNING: Sending out one email should only take a fraction of a second, if you are planning on sending out many emails, or you have a slow domain resolution service, you might want to investigate using a background process like delayed job.
 
+h4. Auto encoding header values
+
+ActionMailer now handles the auto encoding of multibyte characters inside of headers and bodies.
+
+If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII.
+
+For more complex examples, such as defining alternate character sets or self encoding text first, please refer to the Mail library.
+
 h4. Complete List of Action Mailer Methods
 
 There are just three methods that you need to send pretty much any email message:
-- 
cgit v1.2.3


From 60ab54113fa833a1258d687673561b9474964149 Mon Sep 17 00:00:00 2001
From: Mikel Lindsaar 
Date: Tue, 20 Apr 2010 14:45:47 +1000
Subject: Needed to update release notes too

---
 railties/guides/source/3_0_release_notes.textile | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index da69ada7b4..ad09016d8b 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -568,6 +568,8 @@ Action Mailer has been given a new API with TMail being replaced out with the ne
 * The +mail+ delivery method acts in a similar way to Action Controller's +respond_to+, and you can explicitly or implicitly render templates. Action Mailer will turn the email into a multipart email as needed.
 * You can pass a proc to the format.mime_type calls within the mail block and explicitly render specific types of text, or add layouts or different templates. The +render+ call inside the proc is from Abstract Controller and supports the same options.
 * What were mailer unit tests have been moved to functional tests.
+* ActionMailer now delegates all auto encoding of header fields and bodies to Mail Gem
+* ActionMailer will auto encode email bodies and headers for you
 
 Deprecations:
 
-- 
cgit v1.2.3


From adda7516e91943f940136cbfe0a0a0b89b65fb82 Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Tue, 20 Apr 2010 02:07:16 -0700
Subject: minor fix and re-organized description of index action

---
 railties/guides/source/getting_started.textile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 09190f5800..c33d50d055 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -395,7 +395,7 @@ class CreatePosts < ActiveRecord::Migration
 end
 
 
-The above migration creates two methods, +up+, called when you run this migration into the database, and +down+ in case you need to reverse the changes made by this migration at a later date.  The +up+ command in this case creates a +posts+ table with two string columns and a text column.  It also is creating two timestamp fields to track record creation and updating.  More information about Rails migrations can be found in the "Rails Database Migrations":migrations.html guide.
+The above migration creates two methods, +up+, called when you run this migration into the database, and +down+ in case you need to reverse the changes made by this migration at a later date.  The +up+ command in this case 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 information about Rails migrations can be found in the "Rails Database Migrations":migrations.html guide.
 
 At this point, you can use a rake command to run the migration:
 
@@ -504,7 +504,7 @@ def index
 end
 
 
-This code sets the +@posts+ instance variable to an array of all posts in the database. +Post.all+ calls the +Post+ model to return all of the posts that are currently in the database, with no limiting conditions.
++Post.all+ calls the +Post+ model to return all of the posts currently in the database. The result of this call is an array containing the posts which has been saved 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.
 
-- 
cgit v1.2.3


From 606bed1a77e0a0a2baf81d1866c66100de443701 Mon Sep 17 00:00:00 2001
From: Rohit Arondekar 
Date: Tue, 20 Apr 2010 23:23:32 -0700
Subject: Replaced f.error_messages with the new code as generated by rails 3
 b3

---
 railties/guides/source/getting_started.textile | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

(limited to 'railties/guides/source')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index c33d50d055..8538d38374 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -603,7 +603,16 @@ If you take a look at +views/posts/_form.html.erb+ file, you will see the follow
 
 
 <%= form_for(@post) do |f| %>
-  <%= f.error_messages %>
+  <% if @post.errors.any? %>
+  
+

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

+
    + <% @post.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %>
<%= f.label :name %>
-- cgit v1.2.3 From a5955196f2ed8a69c49a1a8c0c617ab91cb8d716 Mon Sep 17 00:00:00 2001 From: Rohit Arondekar Date: Sat, 24 Apr 2010 21:51:25 -0700 Subject: Removed mentions of controller specific layouts. Ticket Ref: http://bit.ly/9dqvBI --- railties/guides/source/getting_started.textile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 8538d38374..6052ac737a 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -363,7 +363,6 @@ The scaffold generator will build 15 files in your application, along with some |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/views/layouts/posts.html.erb |A view to control the overall look and feel of the other post views| |app/helpers/posts_helper.rb |Helper functions to be used from the post views| |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| @@ -551,19 +550,19 @@ TIP: For more details on the rendering process, see "Layouts and Rendering in Ra h4. Customizing the Layout -The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of +layouts+, which are containers for views. When Rails renders a view to the browser, it does so by putting the view's HTML into a layout's HTML. The +rails generate scaffold+ command automatically created a default layout, +app/views/layouts/posts.html.erb+, for the posts. Open this layout in your editor and modify the +body+ tag: +The view is only part of the story of how HTML is displayed in your web browser. Rails also has the concept of +layouts+, which are containers for views. When 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. A 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: - Posts: <%= controller.action_name %> - <%= stylesheet_link_tag 'scaffold' %> + Blog + <%= stylesheet_link_tag :all %> + <%= javascript_include_tag :defaults %> + <%= csrf_meta_tag %> -

<%= notice %>

- <%= yield %> -- cgit v1.2.3 From 8ae5cc8380bf52990ca4b694e2a7acb7d1972f83 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 25 Apr 2010 17:22:39 +1000 Subject: Fixing typo in guide, updating ActionMailer description and making the contributors list alphabetical --- railties/guides/source/credits.html.erb | 8 ++++---- railties/guides/source/getting_started.textile | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/credits.html.erb b/railties/guides/source/credits.html.erb index 4d0d1fe782..e9eb31bcae 100644 --- a/railties/guides/source/credits.html.erb +++ b/railties/guides/source/credits.html.erb @@ -43,6 +43,10 @@ Ruby on Rails Guides: Credits Jeff Dean is a software engineer with Pivotal Labs. <% end %> +<%= author('Mikel Lindsaar', 'raasdnil') do %> + Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby Mail gem and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of RubyX, has a blog and tweets. +<% end %> + <%= author('Cássio Marques', 'cmarques') do %> Cássio Marques is a Brazilian software developer working with different programming languages such as Ruby, JavaScript, CPP and Java, as an independent consultant. He blogs at /* CODIFICANDO */, which is mainly written in Portuguese, but will soon get a new section for posts with English translation. <% end %> @@ -58,7 +62,3 @@ Ruby on Rails Guides: Credits <%= author('Heiko Webers', 'hawe') do %> Heiko Webers is the founder of bauland42, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the Ruby on Rails Security Project. After 10 years of desktop application development, Heiko has rarely looked back. <% end %> - -<%= author('Mikel Lindsaar', 'raasdnil') do %> - Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby Mail gem and core contributor (he helped re-write Action Mailer's API). Mikel has a blog and tweets. -<% end %> diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6052ac737a..df07255939 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -91,7 +91,7 @@ Action Dispatch handles routing of web requests and dispatches them as you want, h5. Action Mailer -Action Mailer is a framework for building e-mail services. You can use Action Mailer to send emails based on flexible templates, or to receive and process incoming email. +Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates. h5. Active Model @@ -1128,7 +1128,7 @@ Then you make the +app/views/posts/show.html.erb+ look like the following: The second render just defines the partial template we want to render, comments/form, Rails is smart enough to spot the forward slash in that string and realise that you want to render the _form.html.erb file in the app/views/comments directory. -The +@post+ object is available any partials rendered in the view because we defined it as an instance variable. +The +@post+ object is available to any partials rendered in the view because we defined it as an instance variable. h3. Deleting Comments @@ -1440,6 +1440,7 @@ h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2 +* April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits:html#raasdnil * April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com * February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits:html#raasdnil * January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits:html#raasdnil -- cgit v1.2.3 From 7b15629b932a42fbf100666220d662c864f5244e Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 25 Apr 2010 20:40:39 +0200 Subject: the names of Rails components have a space, eg "Active Record" --- railties/guides/source/3_0_release_notes.textile | 4 +- .../guides/source/action_mailer_basics.textile | 4 +- railties/guides/source/initialization.textile | 154 ++++++++++----------- railties/guides/source/testing.textile | 4 +- 4 files changed, 83 insertions(+), 83 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index ad09016d8b..ad0878682f 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -568,8 +568,8 @@ Action Mailer has been given a new API with TMail being replaced out with the ne * The +mail+ delivery method acts in a similar way to Action Controller's +respond_to+, and you can explicitly or implicitly render templates. Action Mailer will turn the email into a multipart email as needed. * You can pass a proc to the format.mime_type calls within the mail block and explicitly render specific types of text, or add layouts or different templates. The +render+ call inside the proc is from Abstract Controller and supports the same options. * What were mailer unit tests have been moved to functional tests. -* ActionMailer now delegates all auto encoding of header fields and bodies to Mail Gem -* ActionMailer will auto encode email bodies and headers for you +* Action Mailer now delegates all auto encoding of header fields and bodies to Mail Gem +* Action Mailer will auto encode email bodies and headers for you Deprecations: diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 794dc74900..a2a748c749 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -55,7 +55,7 @@ class UserMailer < ActionMailer::Base end -Here is a quick explanation of the items presented in the preceding method. For a full list of all available options, please have a look further down at the Complete List of ActionMailer user-settable attributes section. +Here is a quick explanation of the items presented in the preceding method. For a full list of all available options, please have a look further down at the Complete List of Action Mailer user-settable attributes section. * default Hash - This is a hash of default values for any email you send, in this case we are setting the :from header to a value for all messages in this class, this can be overridden on a per email basis * +mail+ - The actual email message, we are passing the :to and :subject headers in. @@ -150,7 +150,7 @@ WARNING: Sending out one email should only take a fraction of a second, if you a h4. Auto encoding header values -ActionMailer now handles the auto encoding of multibyte characters inside of headers and bodies. +Action Mailer now handles the auto encoding of multibyte characters inside of headers and bodies. If you are using UTF-8 as your character set, you do not have to do anything special, just go ahead and send in UTF-8 data to the address fields, subject, keywords, filenames or body of the email and ActionMailer will auto encode it into quoted printable for you in the case of a header field or Base64 encode any body parts that are non US-ASCII. diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9182f89f5b..9ce27fa331 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -825,11 +825,11 @@ Now that we've covered the extensive process of what the first line does in this end -As you may be able to tell from the code, this is going through and loading all the Railties for ActiveRecord, ActionController, ActionMailer, ActiveResource. Two other Railties, one for ActiveSupport and one for ActionDispatch were required earlier, but are still covered in this section for continuity reasons. TODO: link. +As you may be able to tell from the code, this is going through and loading all the Railties for Active Record, Action Controller, Action Mailer, Active Resource. Two other Railties, one for Active Support and one for Action Dispatch were required earlier, but are still covered in this section for continuity reasons. TODO: link. h4. ActiveSupport Railtie -From ActiveSupport's README: +From Active Support's README: Active Support is a collection of various utility classes and standard library extensions that were found useful for Rails. @@ -838,9 +838,9 @@ TODO: Quotify. h5. +require 'active_support/railtie'+ -h4. ActiveRecord Railtie +h4. Active Record Railtie -The ActiveRecord Railtie takes care of hooking ActiveRecord into Rails. This depends on ActiveSupport, ActiveModel and Arel. From ActiveRecord's readme: +The Active Record Railtie takes care of hooking Active Record into Rails. This depends on Active Support, Active Model and Arel. From Active Record's readme: TODO: Quotify. @@ -858,9 +858,9 @@ TODO: Quotify. h5. +require "active_record/railtie"+ -The _activerecord/lib/active_record/railtie.rb_ file defines the Railtie for ActiveRecord. +The _activerecord/lib/active_record/railtie.rb_ file defines the Railtie for Active Record. -This file first requires ActiveRecord, the _railties/lib/rails.rb_ file which has already been required and so will be ignored, and the ActiveModel Railtie: +This file first requires Active Record, the _railties/lib/rails.rb_ file which has already been required and so will be ignored, and the Active Model Railtie: require "active_record" @@ -868,13 +868,13 @@ This file first requires ActiveRecord, the _railties/lib/rails.rb_ file which ha require "active_model/railtie" -ActiveModel's Railtie is covered in the next section. TODO: Section. +Active Model's Railtie is covered in the next section. TODO: Section. h5. +require "active_record"+ TODO: Why are +activesupport_path+ and +activemodel_path+ defined here? -The first three requires require ActiveSupport, ActiveModel and ARel in that order: +The first three requires require ActiveSupport, Active Model and ARel in that order: require 'active_support' @@ -885,17 +885,17 @@ The first three requires require ActiveSupport, ActiveModel and ARel in that ord h5. +require "active_support"+ -This was loaded earlier by _railties/lib/rails.rb_. This line is here as a safeguard for when ActiveRecord is loaded outside the scope of Rails. +This was loaded earlier by _railties/lib/rails.rb_. This line is here as a safeguard for when Active Record is loaded outside the scope of Rails. h5. +require "active_model"+ TODO: Again with the +activesupport_path+! -Here we see another +require "active_support"+ this is again, a safeguard for when ActiveModel is loaded outside the scope of Rails. +Here we see another +require "active_support"+ this is again, a safeguard for when Active Model is loaded outside the scope of Rails. -This file defines a few +autoload+'d modules for ActiveModel, requires +active_support/i18n+ and adds the default translation file for ActiveModel to +I18n.load_path+. +This file defines a few +autoload+'d modules for Active Model, requires +active_support/i18n+ and adds the default translation file for Active Model to +I18n.load_path+. -The +require 'active_support/i18n'+ just loads I18n and adds ActiveSupport's default translations file to +I18n.load_path+ too: +The +require 'active_support/i18n'+ just loads I18n and adds Active Support's default translations file to +I18n.load_path+ too: require 'i18n' @@ -905,7 +905,7 @@ The +require 'active_support/i18n'+ just loads I18n and adds ActiveSupport's def h5. +require "arel"+ -This file in _arel/lib/arel.rb_ loads a couple of ActiveSupport things first: +This file in _arel/lib/arel.rb_ loads a couple of Active Support things first: require 'active_support/inflector' @@ -917,7 +917,7 @@ These files are explained in the "Common Includes" section. h5. +require 'arel'+ -Back in _arel/lib/arel.rb_, the next two lines require ActiveRecord parts: +Back in _arel/lib/arel.rb_, the next two lines require Active Record parts: require 'active_record' @@ -928,7 +928,7 @@ Because we're currently loading _active_record.rb_, it skips right over it. h5. +require 'active_record/connection_adapters/abstract/quoting'+ -_activerecord/lib/active_record/connection_adapters/abstract/quoting.rb_ defines methods used for quoting fields and table names in ActiveRecord. +_activerecord/lib/active_record/connection_adapters/abstract/quoting.rb_ defines methods used for quoting fields and table names in Active Record. TODO: Explain why this is loaded especially. @@ -936,11 +936,11 @@ h5. +require 'active_record'+ Back the initial require from the _railtie.rb_. -The _active_support_ and _active_model_ requires are again just an insurance for if we're loading ActiveRecord outside of the scope of Rails. In _active_record.rb_ the ActiveRecord +Module+ is initialized and in it there is defined a couple of +autoloads+ and +eager_autoloads+. +The _active_support_ and _active_model_ requires are again just an insurance for if we're loading Active Record outside of the scope of Rails. In _active_record.rb_ the ActiveRecord +Module+ is initialized and in it there is defined a couple of +autoloads+ and +eager_autoloads+. There's a new method here called +autoload_under+ which is defined in +ActiveSupport::Autoload+. This sets the autoload path to temporarily be the specified path, in this case +relation+ for the +autoload+'d classes inside the block. -Inside this file the +AttributeMethods+, +Locking+ and +ConnectionAdapter+ modules are defined inside the +ActiveRecord+ module. The second to last line tells Arel what SQL engine we want to use. In this case it's +ActiveRecord::Base+. The final line adds in the translations for ActiveRecord which are only for if a record is invalid or non-unique. +Inside this file the +AttributeMethods+, +Locking+ and +ConnectionAdapter+ modules are defined inside the +ActiveRecord+ module. The second to last line tells Arel what SQL engine we want to use. In this case it's +ActiveRecord::Base+. The final line adds in the translations for Active Record which are only for if a record is invalid or non-unique. h5. +require 'rails'+ @@ -948,15 +948,15 @@ As mentioned previously this is skipped over as it has been already loaded. If y h5. +require 'active_model/railtie'+ -This is covered in the ActiveModel Railtie section. TODO: link there. +This is covered in the Active Model Railtie section. TODO: link there. h5. +require 'action_controller/railtie'+ -This is covered in the ActionController Railtie section. TODO: link there. +This is covered in the Action Controller Railtie section. TODO: link there. -h5. The ActiveRecord Railtie +h5. The Active Record Railtie -Inside the ActiveRecord Railtie the +ActiveRecord::Railtie+ class is defined: +Inside the Active Record Railtie the +ActiveRecord::Railtie+ class is defined: module ActiveRecord @@ -983,11 +983,11 @@ By doing this the +ActiveRecord::Railtie+ class gains access to the methods cont As with the engine initializers, these are explained later. -h4. ActiveModel Railtie +h4. Active Model Railtie -This Railtie is +require+'d by ActiveRecord's Railtie. +This Railtie is +require+'d by Active Record's Railtie. -From the ActiveModel readme: +From the Active Model readme: Prior to Rails 3.0, if a plugin or gem developer wanted to be able to have an object interact with Action Pack helpers, it was required to either copy chunks of code from Rails, or monkey patch entire helpers to make them handle objects that did not look like Active Record. This generated code duplication and fragile applications that broke on upgrades. @@ -1009,11 +1009,11 @@ This Railtie file, _activemodel/lib/active_model/railtie.rb_ is quite small and h5. +require "active_model"+ -ActiveModel depends on ActiveSupport and ensures it is required by making a +require 'active_support'+ call. It has already been loaded from _railties/lib/rails.rb_ so will not be reloaded for us here. The file goes on to define the +ActiveModel+ module and all of its autoloaded classes. This file also defines the english translations for some of the validation messages provided by ActiveModel, such as "is not included in the list" and "is reserved". +Active Model depends on Active Support and ensures it is required by making a +require 'active_support'+ call. It has already been loaded from _railties/lib/rails.rb_ so will not be reloaded for us here. The file goes on to define the +ActiveModel+ module and all of its autoloaded classes. This file also defines the english translations for some of the validation messages provided by Active Model, such as "is not included in the list" and "is reserved". h4. Action Controller Railtie -The ActionController Railtie takes care of all the behind-the-scenes code for your controllers; it puts the C into MVC; and does so by implementing the +ActionController::Base+ class which you may recall is where your +ApplicationController+ class descends from. +The Action Controller Railtie takes care of all the behind-the-scenes code for your controllers; it puts the C into MVC; and does so by implementing the +ActionController::Base+ class which you may recall is where your +ApplicationController+ class descends from. h5. +require 'action_controller/railtie'+ @@ -1025,17 +1025,17 @@ This first makes a couple of requires: require "action_view/railtie" -The _action_controller_ file is explained in the very next section. The require to _rails_ is requiring the already-required _railties/lib/rails.rb_. If you wish to know about the require to _action_view/railtie_ this is explained in the ActionView Railtie section. +The _action_controller_ file is explained in the very next section. The require to _rails_ is requiring the already-required _railties/lib/rails.rb_. If you wish to know about the require to _action_view/railtie_ this is explained in the Action View Railtie section. h5. +require 'action_controller+ -This file, _actionpack/lib/action_controller.rb_, defines the ActionController module and its relative autoloads. Before it does any of that it makes two requires: one to _abstract_controller_, explored next, and the other to _action_dispatch_, explored directly after that. +This file, _actionpack/lib/action_controller.rb_, defines the Action Controller module and its relative autoloads. Before it does any of that it makes two requires: one to _abstract_controller_, explored next, and the other to _action_dispatch_, explored directly after that. h5. +require 'abstract_controller'+ +AbstractController+ provides the functionality of TODO. -This file is in _actionpack/lib/abstract_controller.rb_ and begins by attempting to add the path to ActiveSupport to the load path, which it would succeed in if it wasn't already set by anything loaded before it. In this case, it's not going to be set due to Arel already loading it in (TODO: right?). +This file is in _actionpack/lib/abstract_controller.rb_ and begins by attempting to add the path to Active Support to the load path, which it would succeed in if it wasn't already set by anything loaded before it. In this case, it's not going to be set due to Arel already loading it in (TODO: right?). The next thing in this file four +require+ calls: @@ -1059,7 +1059,7 @@ This file was loaded upon the first require of +active_support+ and is not inclu h5. +require 'active_support/core_ext/module/attr_internal'+ -This file is explained in the "Common Includes" section as it is required again later on. See the TODO: section. I also think this may be explained in the ActiveSupport Extensions guide. +This file is explained in the "Common Includes" section as it is required again later on. See the TODO: section. I also think this may be explained in the Active Support Core Extensions guide. h5. +require 'active_support/core_ext/module/delegation'+ @@ -1073,7 +1073,7 @@ After the initial call to +require 'abstract_controller'+, this calls +require ' This file defines the +ActionController+ module and its autoloaded classes. -Here we have a new method called +autoload_under+. This was covered in the ActiveRecord Railtie but it is covered here also just in case you missed or skimmed over it. The +autoload_under+ method is defined in +ActiveSupport::Autoload+ and it sets the autoload path to temporarily be the specified path, in this case by specifying _metal_ it will load the specified +autoload+'d classes from _lib/action_controller/metal_ inside the block. +Here we have a new method called +autoload_under+. This was covered in the Active Record Railtie but it is covered here also just in case you missed or skimmed over it. The +autoload_under+ method is defined in +ActiveSupport::Autoload+ and it sets the autoload path to temporarily be the specified path, in this case by specifying _metal_ it will load the specified +autoload+'d classes from _lib/action_controller/metal_ inside the block. Another new method we have here is called +autoload_at+: @@ -1092,7 +1092,7 @@ Another new method we have here is called +autoload_at+: end -This defines the path of which to find these classes defined at and is most useful for if you have multiple classes defined in a single file, as is the case for this block; all of those classes are defined inside _action_controller/metal/exceptions.rb_ and when ActiveSupport goes looking for them it will look in that file. +This defines the path of which to find these classes defined at and is most useful for if you have multiple classes defined in a single file, as is the case for this block; all of those classes are defined inside _action_controller/metal/exceptions.rb_ and when Active Support goes looking for them it will look in that file. At the end of this file there are a couple more requires: @@ -1101,7 +1101,7 @@ At the end of this file there are a couple more requires: require 'action_view' require 'action_controller/vendor/html-scanner' - # Common ActiveSupport usage in ActionController + # Common Active Support usage in ActionController require 'active_support/concern' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/load_error' @@ -1113,7 +1113,7 @@ At the end of this file there are a couple more requires: h5. +require 'action_view'+ -This is best covered in the ActionView Railtie section, so skip there by TODO: Link / page? +This is best covered in the Action View Railtie section, so skip there by TODO: Link / page? h5. +require 'action_controller/vendor/html-scanner'+ @@ -1129,7 +1129,7 @@ This file defines, as the path implies, attribute accessors for class. These are h5. +require 'active_support/core_ext/load_error'+ -The ActiveSupport Core Extensions (TODO: LINK!) guide has a great coverage of what this file precisely provides. +The Active Support Core Extensions (TODO: LINK!) guide has a great coverage of what this file precisely provides. h5. +require 'active_support/core_ext/module/attr_internal'+ @@ -1145,7 +1145,7 @@ This file was required earlier by Arel and so is not required again. h5. +require 'active_support/core_ext/name_error'+ -This file includes extensions to the +NameError+ class, providing the +missing_name+ and +missing_name?+ methods. For more information see the ActiveSupport extensions guide. +This file includes extensions to the +NameError+ class, providing the +missing_name+ and +missing_name?+ methods. For more information see the Active Support Core Extensions guide. h5. +require 'active_support/inflector'+ @@ -1153,9 +1153,9 @@ This file is explained in the "Common Includes" section. This file was earlier required by Arel and so is not required again. -h5. ActionController Railtie +h5. Action Controller Railtie -So now we come back to the ActionController Railtie with a couple more requires to go before +ActionController::Railtie+ is defined: +So now we come back to the Action Controller Railtie with a couple more requires to go before +ActionController::Railtie+ is defined: require "action_view/railtie" @@ -1164,17 +1164,17 @@ So now we come back to the ActionController Railtie with a couple more requires require "active_support/deprecation" -As explained previously the +action_view/railtie+ file will be explained in the ActionView Railtie section. TODO: link to it. +As explained previously the +action_view/railtie+ file will be explained in the Action View Railtie section. TODO: link to it. h5. +require 'active_support/core_ext/class/subclasses'+ -For an explanation of this file _activesupport/lib/active_support/core_ext/class/subclasses_, see the ActiveSupport Core Extension guide. +For an explanation of this file _activesupport/lib/active_support/core_ext/class/subclasses_, see the Active Support Core Extension guide. h5. +require 'active_support/deprecation/proxy_wrappers'+ This file, _activesupport/lib/active_support/deprecation/proxy_wrappers.rb_, defines a couple of deprecation classes, which are +DeprecationProxy+, +DeprecationObjectProxy+, +DeprecationInstanceVariableProxy+, +DeprecationConstantProxy+ which are all namespaced into +ActiveSupport::Deprecation+. These last three are all subclasses of +DeprecationProxy+. -Why do we mention them here? Beside the obvious-by-now fact that we're covering just about everything about the initialization process in this guide, if you're deprecating something in your library and you use ActiveSupport, you too can use the +DeprecationProxy+ class (and it's subclasses) too. +Why do we mention them here? Beside the obvious-by-now fact that we're covering just about everything about the initialization process in this guide, if you're deprecating something in your library and you use Active Support, you too can use the +DeprecationProxy+ class (and it's subclasses) too. h6. +DeprecationProxy+ @@ -1234,7 +1234,7 @@ This makes more sense in the wider scope of the initializer: h6. +DeprecatedInstanceVariableProxy+ -This isn't actually used anywhere in Rails anymore. It was used previously for when +@request+ and +@params+ were deprecated in Rails 2. It has been kept around as it could be useful for the same purposes in libraries that use ActiveSupport. +This isn't actually used anywhere in Rails anymore. It was used previously for when +@request+ and +@params+ were deprecated in Rails 2. It has been kept around as it could be useful for the same purposes in libraries that use Active Support. h6. +DeprecatedConstantProxy+ @@ -1307,11 +1307,11 @@ This sets up some default behavior for the warnings raised by +ActiveSupport::De } -In the _test_ environment, we will see the deprecation errors displayed in +$stderr+ and in _development_ mode, these are sent to +Rails.logger+ if it exists, otherwise it is output to +$stderr+ in a very similar fashion to the _test_ environment. These are both defined as procs, so ActiveSupport can pass arguments to the +call+ method we call on it when ActiveSupport +warn+. +In the _test_ environment, we will see the deprecation errors displayed in +$stderr+ and in _development_ mode, these are sent to +Rails.logger+ if it exists, otherwise it is output to +$stderr+ in a very similar fashion to the _test_ environment. These are both defined as procs, so Active Support can pass arguments to the +call+ method we call on it when Active Support +warn+. h5. +require 'active_support/deprecation/reporting'+ -This file defines further extensions to the +ActiveSupport::Deprecation+ module, including the +warn+ method which is used from ActiveSupport's +DeprecationProxy+ class and an +attr_accessor+ on the class called +silenced+. This checks that we have a behavior defined, which we do in the _test_ and _development_ environments, and that we're not +silenced+ before warning about deprecations by +call+'ing the +Proc+ time. +This file defines further extensions to the +ActiveSupport::Deprecation+ module, including the +warn+ method which is used from Active Support's +DeprecationProxy+ class and an +attr_accessor+ on the class called +silenced+. This checks that we have a behavior defined, which we do in the _test_ and _development_ environments, and that we're not +silenced+ before warning about deprecations by +call+'ing the +Proc+ time. This file also defines a +silence+ method on the module also which you can pass a block to temporarily silence errors: @@ -1357,9 +1357,9 @@ h5. +require 'action_controller/railties/url_helpers'+ This file defines a +with+ method on +ActionController::Railtie::UrlHelpers+ which is later used in the +action_controller.url_helpers+ initializer. For more information see the +action_controller.url_helpers+ initializer section. -h5. ActionController Railtie +h5. Action Controller Railtie -After these requires it deprecates a couple of ex-ActionController methods and points whomever references them to their ActionDispatch equivalents. These methods are +session+, +session=+, +session_store+ and +session_store=+. +After these requires it deprecates a couple of ex-Action Controller methods and points whomever references them to their ActionDispatch equivalents. These methods are +session+, +session=+, +session_store+ and +session_store=+. After the deprecations, Rails defines the +log_subscriber+ to be a new instance of +ActionController::Railties::LogSubscriber+ and then go about defining the following initializers, keeping in mind that these are added to the list of initializers defined before hand: @@ -1369,9 +1369,9 @@ After the deprecations, Rails defines the +log_subscriber+ to be a new instance * action_controller.set_helpers_path * action_controller.url_helpers -h4. ActionView Railtie +h4. Action View Railtie -The ActionView Railtie provides the backend code for your views and it puts the C into MVC. This implements the +ActionView::Base+ of which all views and partials are objects of. +The Action View Railtie provides the backend code for your views and it puts the C into MVC. This implements the +ActionView::Base+ of which all views and partials are objects of. h5. +require 'action_view/railtie'+ @@ -1379,7 +1379,7 @@ The Railtie is defined in a file called _actionpack/lib/action_view/railtie.rb_ h5. +require 'action_view'+ -Here again we have the addition of the path to ActiveSupport to the load path attempted, but because it's already in the load path it will not be added. Similarly, we have two requires: +Here again we have the addition of the path to Active Support to the load path attempted, but because it's already in the load path it will not be added. Similarly, we have two requires: require 'active_support/ruby/shim' @@ -1489,7 +1489,7 @@ h5. +ActionView::Context+ TODO: Not entirely sure what this is all about. Something about the context of view rendering... can't work it out. -h5. ActionView Railtie +h5. Action View Railtie Now that _actionpack/lib/action_view.rb_ has been required, the next step is to +require 'rails'+, but this will be skipped as the file was required by _railties/lib/rails/all.rb_ way back in the beginnings of the initialization process. @@ -1519,9 +1519,9 @@ The +ActionView::LogSubscriber+ sets up a method called +render_template+ which The sole initializer defined here, _action_view.cache_asset_timestamps_ is responsible for caching the timestamps on the ends of your assets. If you've ever seen a link generated by +image_tag+ or +stylesheet_link_tag+ you would know that I mean that this timestamp is the number after the _?_ in this example: _/javascripts/prototype.js?1265442620_. This initializer will do nothing if +cache_classes+ is set to false in any of your application's configuration. TODO: Elaborate. -h4. ActionMailer Railtie +h4. Action Mailer Railtie -The ActionMailer Railtie is responsible for including all the emailing functionality into Rails by way of the ActionMailer gem itself. ActionMailer is: +The Action Mailer Railtie is responsible for including all the emailing functionality into Rails by way of the Action Mailer gem itself. Action Mailer is: Action Mailer is a framework for designing email-service layers. These layers are used to consolidate code for sending out forgotten passwords, welcome @@ -1549,7 +1549,7 @@ The requires in +action_mailer+ are already loaded or are core extensions: require 'abstract_controller' require 'action_view' - # Common ActiveSupport usage in ActionMailer + # Common Active Support usage in Action Mailer require 'active_support/core_ext/class' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/array/uniq_by' @@ -1559,8 +1559,8 @@ The requires in +action_mailer+ are already loaded or are core extensions: require 'active_support/lazy_load_hooks' -_abstract_controller_ is covered in the "ActionController Railtie" section. TODO: Cover AbstractController there and link to it. -_action_view_ was required by the ActionView Railtie and will not be required again. +_abstract_controller_ is covered in the "Action Controller Railtie" section. TODO: Cover AbstractController there and link to it. +_action_view_ was required by the Action View Railtie and will not be required again. For the core extensions you may reference the "Core Extensions" guide. TODO: Link to guide. @@ -1615,7 +1615,7 @@ which is used by the +ActionMailer::MailerHelper+ method +block_format+: end -h5. ActionMailer Railtie +h5. Action Mailer Railtie The Railtie defines the +log_subscriber+ as +ActionMailer::Railties::LogSubscriber.new+, with this class having two logging methods: one for delivery called +deliver+ and one for receipt called +receive+. @@ -1627,13 +1627,13 @@ The initializers defined in this Railtie are: These are covered later on the Initialization section. TODO: first write then link to Initialization section. -h4. ActiveResource Railtie +h4. Active Resource Railtie -The ActiveResource Railtie is responsible for creating an interface into remote sites that offer a REST API. The ActiveResource Railtie depends on ActiveSupport and ActiveModel. +The Active Resource Railtie is responsible for creating an interface into remote sites that offer a REST API. The Active Resource Railtie depends on Active Support and Active Model. h5. +require 'active_resource/railtie'+ -This file defines the ActiveResource Railtie: +This file defines the Active Resource Railtie: require "active_resource" @@ -1659,7 +1659,7 @@ The +require 'rails'+ has already been done back in TODO: link to section. h5. +require 'active_resource'+ -This file, _activeresource/lib/active_resource.rb_, defines the +ActiveResource+ module, first off this will add the path to ActiveSupport and ActiveModel to the load path if it's not already there, then require both +active_support+ (_activesupport/lib/active_support.rb_) and +active_model+ (_activemodel/lib/active_model.rb_) +This file, _activeresource/lib/active_resource.rb_, defines the +ActiveResource+ module, first off this will add the path to Active Support and Active Model to the load path if it's not already there, then require both +active_support+ (_activesupport/lib/active_support.rb_) and +active_model+ (_activemodel/lib/active_model.rb_) activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__) @@ -1685,9 +1685,9 @@ This file, _activeresource/lib/active_resource.rb_, defines the +ActiveResource+ end -h5. ActiveResource Railtie +h5. Active Resource Railtie -The Railtie itself is fairly short as ActiveResource is the smallest component of Rails. +The Railtie itself is fairly short as Active Resource is the smallest component of Rails. module ActiveResource @@ -1713,11 +1713,11 @@ There is only one initializer defined here: +set_configs+. This is covered later h4. ActionDispatch Railtie -ActionDispatch handles all dispatch work for Rails. It interfaces with ActionController to determine what action to undertake when a request comes in. TODO: I would quote the README but it is strangely absent. Flyin' blind here! +ActionDispatch handles all dispatch work for Rails. It interfaces with Action Controller to determine what action to undertake when a request comes in. TODO: I would quote the README but it is strangely absent. Flyin' blind here! The ActionDispatch Railtie was previously required when we called +require 'rails'+, but we will cover the Railtie here too. -ActionDispatch depends on ActiveSupport. +ActionDispatch depends on Active Support. h5. +require 'action_dispatch/railtie'+ @@ -1755,7 +1755,7 @@ This file was already loaded earlier in the initialization process. TODO: link t h5. ActionDispatch Railtie -The ActionDispatch Railtie is almost as short as the ActiveResource Railtie: +The ActionDispatch Railtie is almost as short as the Active Resource Railtie: require "action_dispatch" @@ -2903,7 +2903,7 @@ If you don't want this to happen you can specify the +config.active_support.bare h4. +preload_frameworks+ -Remember earlier how we had all that stuff +eager_autoload+'d for ActiveSupport? +Remember earlier how we had all that stuff +eager_autoload+'d for Active Support? initializer :preload_frameworks do @@ -2932,11 +2932,11 @@ With +@@autoloads+ being * initialize_dependency_mechanism * bootstrap_load_path -h4. ActiveSupport Initializers +h4. Active Support Initializers -ActiveSupport +Active Support -**ActiveSupport Initializers** +**Active Support Initializers** * active_support.initialize_whiny_nils * active_support.initialize_time_zone @@ -2947,18 +2947,18 @@ ActiveSupport The +I18n::Railtie+ also defines an +after_initialize+ which we will return to later when discussing the initializers in detail. -**ActionDispatch Initializers** +**Action Dispatch Initializers** * action_dispatch.prepare_dispatcher -**ActionController Initializers** +**Action Controller Initializers** * action_controller.logger * action_controller.set_configs * action_controller.initialize_framework_caches * action_controller.set_helpers_path -**ActiveRecord Initializers** +**Active Record Initializers** * active_record.initialize_time_zone * active_record.logger @@ -2968,17 +2968,17 @@ The +I18n::Railtie+ also defines an +after_initialize+ which we will return to l * active_record.load_observers * active_record.set_dispatch_hooks -**ActionView Initializers ** +**Action View Initializers ** * action_view.cache_asset_timestamps -**ActionMailer Initializers ** +**Action Mailer Initializers ** * action_mailer.logger * action_mailer.set_configs * action_mailer.url_for -**ActiveResource Initializers** +**Active Resource Initializers** * active_resource.set_configs @@ -3651,7 +3651,7 @@ This file is _activesupport/lib/active_support/inflector.rb_ and makes a couple require 'active_support/core_ext/string/inflections' -The files included here define methods for modifying strings, such as +transliterate+ which will convert a Unicode string to its ASCII version, +parameterize+ for making strings into url-safe versions, +camelize+ for camel-casing a string such as +string_other+ into +StringOther+ and +ordinalize+ converting a string such as +101+ into +101st+. More information about these methods can be found in the ActiveSupport Guide. TODO: Link to AS Guide. +The files included here define methods for modifying strings, such as +transliterate+ which will convert a Unicode string to its ASCII version, +parameterize+ for making strings into url-safe versions, +camelize+ for camel-casing a string such as +string_other+ into +StringOther+ and +ordinalize+ converting a string such as +101+ into +101st+. More information about these methods can be found in the Active Support Core Extensions Guide. TODO: Link to AS Guide. h4. +require 'active_support/core_ext/module/delegation'+ @@ -3705,6 +3705,6 @@ The _activesupport/lib/active_support/ruby/shim.rb_ file requires methods that h * +Time.to_time+ * +Time.to_datetime+ -For more information see the ActiveSupport Extensions guide TODO: link to relevant sections for each method. +For more information see the Active Support Core Extensions guide TODO: link to relevant sections for each method. And "the REXML security fix detailed here":[http://weblog.rubyonrails.org/2008/8/23/dos-vulnerabilities-in-rexml] diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 206ed6e75c..ca9b10bbd6 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -845,9 +845,9 @@ Testing mailer classes requires some specific tools to do a thorough job. h4. Keeping the Postman in Check -Your +ActionMailer+ classes -- like every other part of your Rails application -- should be tested to ensure that it is working as expected. +Your mailer classes -- like every other part of your Rails application -- should be tested to ensure that it is working as expected. -The goals of testing your +ActionMailer+ classes are to ensure that: +The goals of testing your mailer classes are to ensure that: * emails are being processed (created and sent) * the email content is correct (subject, sender, body, etc) -- cgit v1.2.3 From a5713147558648429dec63df612a487accf48af2 Mon Sep 17 00:00:00 2001 From: eparreno Date: Mon, 26 Apr 2010 22:32:10 +0200 Subject: fix font formats and code examples indentation --- railties/guides/source/testing.textile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index ca9b10bbd6..8d7d73b487 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -146,14 +146,14 @@ NOTE: For more information on Rails scaffolding, refer to "Getting Starte When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: -
+
 $ rails generate scaffold post title:string body:text
 ...
 create  app/models/post.rb
 create  test/unit/post_test.rb
 create  test/fixtures/posts.yml
 ...
-
+ The default test stub in +test/unit/post_test.rb+ looks like this: @@ -702,24 +702,24 @@ class UserFlowsTest < ActionController::IntegrationTest private - module CustomDsl - def browses_site - get "/products/all" - assert_response :success - assert assigns(:products) - end + module CustomDsl + def browses_site + get "/products/all" + assert_response :success + assert assigns(:products) end + end - def login(user) - open_session do |sess| - sess.extend(CustomDsl) - u = users(user) - sess.https! - sess.post "/login", :username => u.username, :password => u.password - assert_equal '/welcome', path - sess.https!(false) - end + def login(user) + open_session do |sess| + sess.extend(CustomDsl) + u = users(user) + sess.https! + sess.post "/login", :username => u.username, :password => u.password + assert_equal '/welcome', path + sess.https!(false) end + end end
-- cgit v1.2.3 From 97b39363184d3373fce021558012d46ce4cb4977 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 27 Apr 2010 22:43:55 +0200 Subject: release notes: updates path to the rails command in the Rails repo --- railties/guides/source/3_0_release_notes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index ad0878682f..66fdad8c54 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -102,7 +102,7 @@ $ rails myapp --edge If you have a local checkout of the Rails repository and want to generate an application using that, you can pass the +--dev+ flag: -$ ruby /path/to/rails/railties/bin/rails myapp --dev +$ ruby /path/to/rails/bin/rails myapp --dev h3. Rails Architectural Changes -- cgit v1.2.3 From 033b1e68c070eca9da7ad216e56a2cbbaddba74d Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 08:06:28 +0530 Subject: added views dir to list of created things --- railties/guides/source/getting_started.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index df07255939..36e37a1c5d 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -886,12 +886,13 @@ With the model in hand, you can turn your attention to creating a matching contr $ rails generate controller Comments -This creates four files: +This creates four 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 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 the post show page to see their comment now listed. Due to this, our +CommentsController+ is there to provide a method to create comments and delete SPAM comments when they arrive. -- cgit v1.2.3 From c6a83378519a7ee9e16adec0fe25736fd794d971 Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 08:09:27 +0530 Subject: added notice to all samples of show.html.erb of posts controller --- railties/guides/source/getting_started.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 36e37a1c5d..ff79d9c0ab 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -686,6 +686,8 @@ 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+: +

<%= notice %>

+

Name: <%= @post.name %> @@ -899,6 +901,8 @@ Like with any blog, our readers will create their comments directly after readin So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+) to let us make a new comment: +

<%= notice %>

+

Name: <%= @post.name %> @@ -954,6 +958,8 @@ In addition, the code takes advantage of some of the methods available for an as Once we have made the new comment, we send the user back to the +post_path(@post)+ URL. This runs the +show+ action of the +PostsController+ which then renders the +show.html.erb+ template where we want the comment to show, so then, we'll add that to the +app/view/posts/show.html.erb+. +

<%= notice %>

+

Name: <%= @post.name %> @@ -1030,6 +1036,8 @@ First will make a comment partial to extract showing all the comments for the po Then in the +app/views/posts/show.html.erb+ you can change it to look like the following: +

<%= notice %>

+

Name: <%= @post.name %> @@ -1099,6 +1107,8 @@ Lets also move that new comment section out to it's own partial, again, you crea Then you make the +app/views/posts/show.html.erb+ look like the following: +

<%= notice %>

+

Name: <%= @post.name %> @@ -1337,6 +1347,8 @@ Now create the folder app/views/tags and make a file in there called app/views/posts/show.html.erb template to show our tags. +

<%= notice %>

+

Name: <%= @post.name %> @@ -1390,6 +1402,8 @@ end Now you can edit the view in app/views/posts/show.html.erb to look like this: +

<%= notice %>

+

Name: <%= @post.name %> -- cgit v1.2.3 From 56c48f8136b2008e18c712b8133e83edd08e27b1 Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 10:38:06 +0530 Subject: Fixed incomplete para --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index ff79d9c0ab..d310489a12 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -953,7 +953,7 @@ end You'll see a bit more complexity here than you did in the controller for posts. That's a side-effect of the nesting that you've set up; each request for a comment has to keep track of the post to which the comment is attached, thus the initial find action to the Post model to get the post in question. -In addition, the code takes advantage of some of the methods available for an association. For example, in the +new+ method, it calls +In addition, the code takes advantage of some of the methods available for an association. We use the +create+ method on +@post.comments+ to create and save the comment. This will automatically link the comment so that it belongs to that particular post. Once we have made the new comment, we send the user back to the +post_path(@post)+ URL. This runs the +show+ action of the +PostsController+ which then renders the +show.html.erb+ template where we want the comment to show, so then, we'll add that to the +app/view/posts/show.html.erb+. -- cgit v1.2.3 From 9dea2f4d8edf3cc592c91e1037b1542f770eff0c Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 10:43:36 +0530 Subject: fixed para for better readability --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index d310489a12..f5be0b34c4 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -955,7 +955,7 @@ You'll see a bit more complexity here than you did in the controller for posts. In addition, the code takes advantage of some of the methods available for an association. We use the +create+ method on +@post.comments+ to create and save the comment. This will automatically link the comment so that it belongs to that particular post. -Once we have made the new comment, we send the user back to the +post_path(@post)+ URL. This runs the +show+ action of the +PostsController+ which then renders the +show.html.erb+ template where we want the comment to show, so then, we'll add that to the +app/view/posts/show.html.erb+. +Once we have made the new comment, we send the user back to the original post using the +post_path(@post)+ helper. As we have already seen, this calls the +show+ action of the +PostsController+ which in turn renders the +show.html.erb+ template. This is where we want the comment to show, so let's add that to the +app/view/posts/show.html.erb+.

<%= notice %>

-- cgit v1.2.3 From edcbd33785b41fd5e01a862d7432da5d74532529 Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 10:48:55 +0530 Subject: replaced tag with tag in samples --- railties/guides/source/getting_started.textile | 58 +++++++++++++------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index f5be0b34c4..5365936903 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -689,17 +689,17 @@ The +show+ action uses +Post.find+ to search for a single record in the database

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

@@ -904,17 +904,17 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

@@ -961,29 +961,29 @@ Once we have made the new comment, we send the user back to the original post us

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

Comments

<% @post.comments.each do |comment| %>

- Commenter: + Commenter: <%= comment.commenter %>

- Comment: + Comment: <%= comment.body %>

<% end %> @@ -1023,12 +1023,12 @@ First will make a comment partial to extract showing all the comments for the po

- Commenter: + Commenter: <%= comment.commenter %>

- Comment: + Comment: <%= comment.body %>

@@ -1039,17 +1039,17 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

@@ -1110,17 +1110,17 @@ Then you make the +app/views/posts/show.html.erb+ look like the following:

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

@@ -1149,12 +1149,12 @@ So first, let's add the delete link in the +app/views/comments/_comment.html.erb

- Commenter: + Commenter: <%= comment.commenter %>

- Comment: + Comment: <%= comment.body %>

@@ -1350,22 +1350,22 @@ Finally, we will edit the app/views/posts/show.html.erb template to sho

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

- Tags: + Tags: <%= @post.tags.map { |t| t.name }.join(", ") %>

@@ -1405,22 +1405,22 @@ Now you can edit the view in app/views/posts/show.html.erb to look like

<%= notice %>

- Name: + Name: <%= @post.name %>

- Title: + Title: <%= @post.title %>

- Content: + Content: <%= @post.content %>

- Tags: + Tags: <%= join_tags(@post) %>

-- cgit v1.2.3 From 8f1a5bfee1305f193bb659c010ca7e2272c12051 Mon Sep 17 00:00:00 2001 From: rohit Date: Wed, 28 Apr 2010 11:21:45 +0530 Subject: readability fixes to two paras in Refactorization --- railties/guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 5365936903..a4f969efe9 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1015,11 +1015,11 @@ Now you can add posts and comments to your blog and have them show up in the rig h3. Refactorization -Now that we have Posts and Comments working, we can take a look at the +app/views/posts/show.html.erb+ template, it is getting long and awkward, we can use partials to clean this up. +Now that we have Posts and Comments working, if we take a look at the +app/views/posts/show.html.erb+ template, it's getting long and awkward. We can use partials to clean this up. h4. Rendering Partial Collections -First will make a comment partial to extract showing all the comments for the post, so make a file +app/views/comments/_comment.html.erb+ and put into it: +First we will make a comment partial to extract showing all the comments for the post. Create the file +app/views/comments/_comment.html.erb+ and put the following into it:

-- cgit v1.2.3 From 34908e4a666971216a92b58d8c62030b9a96b7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Apr 2010 12:50:42 +0200 Subject: Updated the generators guide. --- railties/guides/source/generators.textile | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index 4387fe3bd5..d3757e9733 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -88,9 +88,7 @@ And it will create a new generator as follow: class InitializerGenerator < Rails::Generators::NamedBase - def self.source_root - @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) - end + source_root File.expand_path("../templates", __FILE__) end @@ -115,9 +113,7 @@ And now let's change the generator to copy this template when invoked: class InitializerGenerator < Rails::Generators::NamedBase - def self.source_root - @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) - end + source_root File.expand_path("../templates", __FILE__) def copy_initializer_file copy_file "initializer.rb", "config/initializers/#{file_name}.rb" @@ -135,21 +131,18 @@ We can see that now a initializer named foo was created at +config/initializers/ h3. Generators lookup -Now that we know how to create generators, we must know where Rails looks for generators before invoking them. When we invoke the initializer generator, Rails looks at the following paths in the given order: +With our first generator created, we must discuss briefly generators lookup. The way Rails finds generators is exactly the same way Ruby find files, i.e. using +$LOAD_PATHS+. + +For instance, when you say +rails g initializer foo+, rails knows you want to invoke the initializer generator and then search for the following generators in the $LOAD_PATHS: -RAILS_APP/lib/generators -RAILS_APP/lib/rails_generators -RAILS_APP/vendor/plugins/*/lib/generators -RAILS_APP/vendor/plugins/*/lib/rails_generators -GEMS_PATH/*/lib/generators -GEMS_PATH/*/lib/rails_generators -~/rails/generators -~/rails/rails_generators -RAILS_GEM/lib/rails/generators +rails/generators/initializer/initializer_generator.rb +generators/initializer/initializer_generator.rb +rails/generators/initializer_generator.rb +generators/initializer_generator.rb -First Rails looks for generators in your application, then in plugins and/or gems, then in your home and finally the builtin generators. One very important thing to keep in mind is that in Rails 3.0 and after it only looks for generators in gems being used in your application. So if you have rspec installed as a gem, but it's not declared in your application, Rails won't be able to invoke it. +If none of them is found, it raises an error message. h3. Customizing your workflow @@ -183,7 +176,6 @@ $ rails generate scaffold User name:string create app/views/users/show.html.erb create app/views/users/new.html.erb create app/views/users/_form.html.erb - create app/views/layouts/users.html.erb invoke test_unit create test/functional/users_controller_test.rb invoke helper @@ -284,7 +276,7 @@ end end -Now, when the helper generator is invoked and let's say test unit is configured as test framework, it will try to invoke both +MyHelper::Generators::TestUnitGenerator+ and +TestUnit::Generators::MyHelperGenerator+. Since none of those are defined, we can tell our generator to invoke +TestUnit::Generators::HelperGenerator+ instead, which is defined since it's a Rails hook. To do that, we just need to add: +Now, when the helper generator is invoked and let's say test unit is configured as test framework, it will try to invoke both +MyHelper::Generators::TestUnitGenerator+ and +TestUnit::Generators::MyHelperGenerator+. Since none of those are defined, we can tell our generator to invoke +TestUnit::Generators::HelperGenerator+ instead, which is defined since it's a Rails generator. To do that, we just need to add: # Search for :helper instead of :my_helper @@ -375,4 +367,6 @@ h3. Changelog "Lighthouse Ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/102 -* November 20, 2009: First release version by José Valim +* April 30, 2010: Reviewed by José Valim + +* November 20, 2009: First version by José Valim -- cgit v1.2.3