diff options
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/3_0_release_notes.textile | 4 | ||||
-rw-r--r-- | railties/guides/source/action_mailer_basics.textile | 10 | ||||
-rw-r--r-- | railties/guides/source/command_line.textile | 42 | ||||
-rw-r--r-- | railties/guides/source/credits.html.erb | 8 | ||||
-rw-r--r-- | railties/guides/source/generators.textile | 34 | ||||
-rw-r--r-- | railties/guides/source/getting_started.textile | 114 | ||||
-rw-r--r-- | railties/guides/source/initialization.textile | 154 | ||||
-rw-r--r-- | railties/guides/source/performance_testing.textile | 20 | ||||
-rw-r--r-- | railties/guides/source/testing.textile | 38 |
9 files changed, 226 insertions, 198 deletions
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index da69ada7b4..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: <shell> -$ ruby /path/to/rails/railties/bin/rails myapp --dev +$ ruby /path/to/rails/bin/rails myapp --dev </shell> h3. Rails Architectural Changes @@ -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 <tt>format.mime_type</tt> 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. +* 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 79cb86ee97..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 </ruby> -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. * <tt>default Hash</tt> - This is a hash of default values for any email you send, in this case we are setting the <tt>:from</tt> 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 <tt>:to</tt> and <tt>:subject</tt> headers in. @@ -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 + +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. + +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: diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index ebae320ebc..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 <shell> $ 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 </shell> 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. @@ -237,7 +238,7 @@ The migration requires that we *migrate*, that is, run some Ruby code (living in <shell> $ rake db:migrate -(in /Users/mikel/rails_programs/commandsapp) +(in /home/foobar/commandsapp) == CreateHighScores: migrating =============================================== -- create_table(:high_scores) -> 0.0026s @@ -320,21 +321,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. <shell> -$ 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/foobar/commandsapp Environment development -Database adapter sqlite3 -Database schema version 20081217073400 </shell> h3. The Rails Advanced Command Line @@ -526,7 +526,7 @@ You can get a list of Rake tasks available to you, which will often depend on yo <shell> 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 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 <a href="http://pivotallabs.com">Pivotal Labs</a>. <% end %> +<%= author('Mikel Lindsaar', 'raasdnil') do %> + Mikel Lindsaar has been working with Rails since 2006 and is the author of the Ruby <a hred="http://github.com/mikel/mail">Mail gem</a> and core contributor (he helped re-write Action Mailer's API). Mikel is the founder of <a href="http://rubyx.com/">RubyX</a>, has a <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>. +<% 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 <a href="http://cassiomarques.wordpress.com">/* CODIFICANDO */</a>, 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 <a href="http://www.bauland42.de">bauland42</a>, a German web application security consulting and development company focused on Ruby on Rails. He blogs at the <a href="http://www.rorsecurity.info">Ruby on Rails Security Project</a>. 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 <a href="http://lindsaar.net/">blog</a> and <a href="http://twitter.com/raasdnil">tweets</a>. -<% end %> 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: <ruby> 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 </ruby> @@ -115,9 +113,7 @@ And now let's change the generator to copy this template when invoked: <ruby> 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: <shell> -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 </shell> -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 </ruby> -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: <ruby> # 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 diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 09190f5800..a4f969efe9 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 @@ -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| @@ -395,7 +394,7 @@ class CreatePosts < ActiveRecord::Migration end </ruby> -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 +503,7 @@ def index end </ruby> -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. @@ -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: <erb> <!DOCTYPE html> <html> <head> - <title>Posts: <%= controller.action_name %></title> - <%= stylesheet_link_tag 'scaffold' %> + <title>Blog</title> + <%= stylesheet_link_tag :all %> + <%= javascript_include_tag :defaults %> + <%= csrf_meta_tag %> </head> <body style="background: #EEEEEE;"> -<p class="notice"><%= notice %></p> - <%= yield %> </body> @@ -603,7 +602,16 @@ If you take a look at +views/posts/_form.html.erb+ file, you will see the follow <erb> <%= form_for(@post) do |f| %> - <%= f.error_messages %> + <% if @post.errors.any? %> + <div id="errorExplanation"> + <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> + <ul> + <% @post.errors.full_messages.each do |msg| %> + <li><%= msg %></li> + <% end %> + </ul> + </div> + <% end %> <div class="field"> <%= f.label :name %><br /> @@ -678,18 +686,20 @@ 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+: <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> @@ -878,30 +888,33 @@ With the model in hand, you can turn your attention to creating a matching contr $ rails generate controller Comments </shell> -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. So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+) to let us make a new comment: <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> @@ -940,35 +953,37 @@ 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+. +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+. <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> <h2>Comments</h2> <% @post.comments.each do |comment| %> <p> - <b>Commenter:</b> + <strong>Commenter:</strong> <%= comment.commenter %> </p> <p> - <b>Comment:</b> + <strong>Comment:</strong> <%= comment.body %> </p> <% end %> @@ -1000,20 +1015,20 @@ 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: <erb> <p> - <b>Commenter:</b> + <strong>Commenter:</strong> <%= comment.commenter %> </p> <p> - <b>Comment:</b> + <strong>Comment:</strong> <%= comment.body %> </p> </erb> @@ -1021,18 +1036,20 @@ 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: <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> @@ -1090,18 +1107,20 @@ 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: <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> @@ -1120,7 +1139,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, <tt>comments/form</tt>, Rails is smart enough to spot the forward slash in that string and realise that you want to render the <tt>_form.html.erb</tt> file in the <tt>app/views/comments</tt> 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 @@ -1130,12 +1149,12 @@ So first, let's add the delete link in the +app/views/comments/_comment.html.erb <erb> <p> - <b>Commenter:</b> + <strong>Commenter:</strong> <%= comment.commenter %> </p> <p> - <b>Comment:</b> + <strong>Comment:</strong> <%= comment.body %> </p> @@ -1328,23 +1347,25 @@ Now create the folder <tt>app/views/tags</tt> and make a file in there called <t Finally, we will edit the <tt>app/views/posts/show.html.erb</tt> template to show our tags. <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> <p> - <b>Tags:</b> + <strong>Tags:</strong> <%= @post.tags.map { |t| t.name }.join(", ") %> </p> @@ -1381,23 +1402,25 @@ end Now you can edit the view in <tt>app/views/posts/show.html.erb</tt> to look like this: <erb> +<p class="notice"><%= notice %></p> + <p> - <b>Name:</b> + <strong>Name:</strong> <%= @post.name %> </p> <p> - <b>Title:</b> + <strong>Title:</strong> <%= @post.title %> </p> <p> - <b>Content:</b> + <strong>Content:</strong> <%= @post.content %> </p> <p> - <b>Tags:</b> + <strong>Tags:</strong> <%= join_tags(@post) %> </p> @@ -1432,6 +1455,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 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 </ruby> -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: <ruby> require "active_record" @@ -868,13 +868,13 @@ This file first requires ActiveRecord, the _railties/lib/rails.rb_ file which ha require "active_model/railtie" </ruby> -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: <ruby> 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: <ruby> 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: <ruby> 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: <ruby> 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: <ruby> 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: <plain> 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" </ruby> -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 </ruby> -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: <ruby> 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" </ruby> -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 } </ruby> -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: <ruby> 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' </ruby> -_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 </ruby> -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: <ruby> 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_) <ruby> activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__) @@ -1685,9 +1685,9 @@ This file, _activeresource/lib/active_resource.rb_, defines the +ActiveResource+ end </ruby> -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. <ruby> 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: <ruby> 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? <ruby> 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' </ruby> -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/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+: <shell> 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 </shell> h5(#output-profiling). Profiling diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index 206ed6e75c..8d7d73b487 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -146,14 +146,14 @@ NOTE: For more information on Rails <i>scaffolding</i>, 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: -<pre> +<shell> $ rails generate scaffold post title:string body:text ... create app/models/post.rb create test/unit/post_test.rb create test/fixtures/posts.yml ... -</pre> +</shell> 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 </ruby> @@ -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) |