From 203626867934a2772a5a3f096521b56d59273407 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Thu, 4 Feb 2010 01:44:54 -0500 Subject: Link to main Arel repository Signed-off-by: Jeremy Kemper --- railties/guides/source/3_0_release_notes.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 5e96f8cf06..7679302ff9 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -8,7 +8,7 @@ Even if you don't give a hoot about any of our internal cleanups, Rails 3.0 is g * Brand new router with an emphasis on RESTful declarations * New Action Mailer API modelled after Action Controller (now without the agonizing pain of sending multipart messages!) -* New Active Record chainable query language built on top of relational algebra +* New Active Record chainable query language built on top of "Arel":http://github.com/brynary/arel, a relational algebra engine * Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS) * Explicit dependency management with Bundler @@ -131,7 +131,7 @@ More Information: - "Rails Edge Architecture":http://yehudakatz.com/2009/06/11/r h4. Arel Integration -"Arel":http://github.com/rails/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record. +"Arel":http://github.com/brynary/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record. More information: - "Why I wrote Arel":http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-wrote-arel/. -- cgit v1.2.3 From f1e5642fb7e99ed5c26e863596bc2ea1e7176fba Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 5 Feb 2010 09:12:35 -0800 Subject: Revert "Link to main Arel repository" This reverts commit 203626867934a2772a5a3f096521b56d59273407. --- railties/guides/source/3_0_release_notes.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 7679302ff9..5e96f8cf06 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -8,7 +8,7 @@ Even if you don't give a hoot about any of our internal cleanups, Rails 3.0 is g * Brand new router with an emphasis on RESTful declarations * New Action Mailer API modelled after Action Controller (now without the agonizing pain of sending multipart messages!) -* New Active Record chainable query language built on top of "Arel":http://github.com/brynary/arel, a relational algebra engine +* New Active Record chainable query language built on top of relational algebra * Unobtrusive JavaScript helpers with drivers for Prototype, jQuery, and more coming (end of inline JS) * Explicit dependency management with Bundler @@ -131,7 +131,7 @@ More Information: - "Rails Edge Architecture":http://yehudakatz.com/2009/06/11/r h4. Arel Integration -"Arel":http://github.com/brynary/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record. +"Arel":http://github.com/rails/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record. More information: - "Why I wrote Arel":http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-wrote-arel/. -- cgit v1.2.3 From f44a0b1d524064a2e919cd10d3013db680af9b17 Mon Sep 17 00:00:00 2001 From: RomD Date: Sat, 6 Feb 2010 17:18:10 +0100 Subject: fix usage examples and more to use new invocations Signed-off-by: Carl Lerche --- railties/guides/source/3_0_release_notes.textile | 6 +-- .../guides/source/action_mailer_basics.textile | 6 +-- .../source/active_support_core_extensions.textile | 2 +- .../activerecord_validations_callbacks.textile | 2 +- railties/guides/source/command_line.textile | 58 +++++++++++----------- .../source/debugging_rails_applications.textile | 12 ++--- railties/guides/source/generators.textile | 28 +++++------ railties/guides/source/getting_started.textile | 26 +++++----- railties/guides/source/migrations.textile | 10 ++-- railties/guides/source/performance_testing.textile | 16 +++--- railties/guides/source/plugins.textile | 28 +++++------ railties/guides/source/rails_on_rack.textile | 10 ++-- railties/guides/source/testing.textile | 8 +-- 13 files changed, 106 insertions(+), 106 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 5e96f8cf06..1624172176 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -39,8 +39,8 @@ h4. script/* replaced by script/rails The new script/rails replaces all the scripts that used to be in the script directory. You do not run script/rails directly though, the +rails+ command detects it is being invoked in the root of a Rails application and runs the script for you. Intended usage is: -rails console # => ./script/console -rails g scaffold post title:string # => ./script/generate scaffold post title:string +rails console # => ./script/rails console +rails g scaffold post title:string # => ./script/rails generate scaffold post title:string Run rails --help for a list of all the options. @@ -557,4 +557,4 @@ h3. Credits See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails 3. Kudos to all of them. -Rails 3.0 Release Notes were compiled by "Mikel Lindsaar":http://lindsaar.net. \ No newline at end of file +Rails 3.0 Release Notes were compiled by "Mikel Lindsaar":http://lindsaar.net. diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 2405b8f28c..941c2e9771 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -19,7 +19,7 @@ h4. Walkthrough to Generating a Mailer h5. Create the Mailer -./script/generate mailer UserMailer +rails generate mailer UserMailer create app/mailers/user_mailer.rb invoke erb create app/views/user_mailer @@ -111,7 +111,7 @@ Let's see how we would go about wiring it up using an observer. First off, we need to create a simple +User+ scaffold: -$ script/generate scaffold user name:string email:string login:string +$ rails generate scaffold user name:string email:string login:string $ rake db:migrate @@ -333,7 +333,7 @@ Receiving and parsing emails with Action Mailer can be a rather complex endeavou * Implement a +receive+ method in your mailer. -* Configure your email server to forward emails from the address(es) you would like your app to receive to +/path/to/app/script/runner 'UserMailer.receive(STDIN.read)'+. +* Configure your email server to forward emails from the address(es) you would like your app to receive to +/path/to/app/script/rails runner 'UserMailer.receive(STDIN.read)'+. Once a method called +receive+ is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer +receive+ instance method. Here's an example: diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 3073c3a7a5..bf39ed4c9f 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1805,7 +1805,7 @@ Rails hijacks +LoadError.new+ to return a +MissingSourceFile+ exception: $ ruby -e 'require "nonexistent"' ...: no such file to load -- nonexistent (LoadError) ... -$ script/runner 'require "nonexistent"' +$ rails runner 'require "nonexistent"' ...: no such file to load -- nonexistent (MissingSourceFile) ... diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 9d0ee29ff2..dc61021f76 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -44,7 +44,7 @@ class Person < ActiveRecord::Base end -We can see how it works by looking at some script/console output: +We can see how it works by looking at some +rails console+ output: >> p = Person.new(:name => "John Doe") diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 1a571358a1..a84e928731 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -58,7 +58,7 @@ Without any prodding of any kind, +server+ will run our new shiny Rails app: $ cd commandsapp -$ ./script/server +$ 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 @@ -76,8 +76,8 @@ h4. +generate+ The +generate+ command uses templates to create a whole lot of things. You can always find out what's available by running +generate+ by itself. Let's do that: -$ ./script/generate -Usage: ./script/generate generator [options] [args] +$ rails generate +Usage: rails generate generator [options] [args] ... ... @@ -95,17 +95,17 @@ Using generators will save you a large amount of time by writing *boilerplate co Let's make our own controller with the controller generator. But what command should we use? Let's ask the generator: -INFO: All Rails console utilities have help text. As with most *NIX utilities, you can try adding +--help+ or +-h+ to the end, for example +./script/server --help+. +INFO: All Rails console utilities have help text. As with most *NIX utilities, you can try adding +--help+ or +-h+ to the end, for example +rails server --help+. -$ ./script/generate controller -Usage: ./script/generate controller ControllerName [options] +$ rails generate controller +Usage: rails generate controller ControllerName [options] ... ... Example: - ./script/generate controller CreditCard open debit credit close + rails generate controller CreditCard open debit credit close Credit card controller with URLs like /credit_card/debit. Controller: app/controllers/credit_card_controller.rb @@ -114,7 +114,7 @@ Example: Test: test/functional/credit_card_controller_test.rb Modules Example: - ./script/generate controller 'admin/credit_card' suspend late_fee + rails generate controller 'admin/credit_card' suspend late_fee Credit card admin controller with URLs /admin/credit_card/suspend. Controller: app/controllers/admin/credit_card_controller.rb @@ -126,7 +126,7 @@ Modules Example: Ah, the controller generator is expecting parameters in the form of +generate controller ControllerName action1 action2+. Let's make a +Greetings+ controller with an action of *hello*, which will say something nice to us. -$ ./script/generate controller Greetings hello +$ rails generate controller Greetings hello exists app/controllers/ exists app/helpers/ create app/views/greetings @@ -157,10 +157,10 @@ Then the view, to display our nice message (in +app/views/greetings/hello.html.e

<%= @message %>

-Deal. Go check it out in your browser. Fire up your server. Remember? +./script/server+ at the root of your Rails application should do it. +Deal. Go check it out in your browser. Fire up your server. Remember? +rails server+ at the root of your Rails application should do it. -$ ./script/server +$ rails server => Booting WEBrick... @@ -173,13 +173,13 @@ INFO: With a normal, plain-old Rails application, your URLs will generally follo "What about data, though?", you ask over a cup of coffee. Rails comes with a generator for data models too. Can you guess its generator name? -$ ./script/generate model -Usage: ./script/generate model ModelName [field:type, field:type] +$ rails generate model +Usage: rails generate model ModelName [field:type, field:type] ... Examples: - ./script/generate model account + rails generate model account creates an Account model, test, fixture, and migration: Model: app/models/account.rb @@ -187,7 +187,7 @@ Examples: Fixtures: test/fixtures/accounts.yml Migration: db/migrate/XXX_add_accounts.rb - ./script/generate model post title:string body:text published:boolean + rails generate model post title:string body:text published:boolean creates a Post model with a string title, text body, and published flag. @@ -197,7 +197,7 @@ But instead of generating a model directly (which we'll be doing later), let's s Let's set up a simple resource called "HighScore" that will keep track of our highest score on video games we play. -$ ./script/generate scaffold HighScore game:string score:integer +$ rails generate scaffold HighScore game:string score:integer exists app/models/ exists app/controllers/ exists app/helpers/ @@ -244,13 +244,13 @@ $ rake db:migrate INFO: Let's talk about unit tests. Unit tests are code that tests and makes assertions about code. In unit testing, we take a little part of code, say a method of a model, and test its inputs and outputs. Unit tests are your friend. The sooner you make peace with the fact that your quality of life will drastically increase when you unit test your code, the better. Seriously. We'll make one in a moment. -Let's see the interface Rails created for us. ./script/server; http://localhost:3000/high_scores +Let's see the interface Rails created for us. rails server; http://localhost:3000/high_scores We can create new high scores (55,160 on Space Invaders!) h4. +console+ -The +console+ command lets you interact with your Rails application from the command line. On the underside, +script/console+ uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website. +The +console+ command lets you interact with your Rails application from the command line. On the underside, +rails console+ uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website. h4. +dbconsole+ @@ -265,7 +265,7 @@ Let's say you're creating a website for a client who wants a small accounting sy There is such a thing! The plugin we're installing is called "acts_as_paranoid", and it lets models implement a "deleted_at" column that gets set when you call destroy. Later, when calling find, the plugin will tack on a database check to filter out "deleted" things. -$ ./script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid +$ rails plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_paranoid + ./CHANGELOG + ./MIT-LICENSE ... @@ -277,7 +277,7 @@ h4. +runner+ runner runs Ruby code in the context of Rails non-interactively. For instance: -$ ./script/runner "Model.long_running_method" +$ rails runner "Model.long_running_method" h4. +destroy+ @@ -285,7 +285,7 @@ h4. +destroy+ Think of +destroy+ as the opposite of +generate+. It'll figure out what generate did, and undo it. Believe you-me, the creation of this tutorial used this command many times! -$ ./script/generate model Oops +$ rails generate model Oops exists app/models/ exists test/unit/ exists test/fixtures/ @@ -294,7 +294,7 @@ $ ./script/generate model Oops create test/fixtures/oops.yml exists db/migrate create db/migrate/20081221040817_create_oops.rb -$ ./script/destroy model Oops +$ rails destroy model Oops notempty db/migrate notempty db rm db/migrate/20081221040817_create_oops.rb @@ -314,7 +314,7 @@ 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. -$ ./script/about +$ rails about About your application's environment Ruby version 1.8.6 (i486-linux) RubyGems version 1.3.1 @@ -399,7 +399,7 @@ Many people have created a large number different web servers in Ruby, and many NOTE: For more details on the Rack integration, see "Rails on Rack":rails_on_rack.html. -To use a different server, just install its gem, then use its name for the first parameter to +script/server+: +To use a different server, just install its gem, then use its name for the first parameter to +rails server+: $ sudo gem install mongrel @@ -412,9 +412,9 @@ Successfully installed mongrel-1.1.5 ... ... Installing RDoc documentation for mongrel-1.1.5... -$ script/server mongrel -=> Booting Mongrel (use 'script/server webrick' to force WEBrick) -=> Rails 2.2.0 application starting on http://0.0.0.0:3000 +$ rails server mongrel +=> Booting Mongrel (use 'rails server webrick' to force WEBrick) +=> Rails 3.0.0 application starting on http://0.0.0.0:3000 ... @@ -481,7 +481,7 @@ I got assigned some args: Then we'll make sure it got included in the list of available generators: -$ ./script/generate +$ rails generate ... ... Installed Generators @@ -491,7 +491,7 @@ Installed Generators SWEET! Now let's generate some text, yeah! -$ ./script/generate tutorial_test arg1 arg2 arg3 +$ rails generate tutorial_test arg1 arg2 arg3 exists public create public/tutorial.txt diff --git a/railties/guides/source/debugging_rails_applications.textile b/railties/guides/source/debugging_rails_applications.textile index 94411a560e..cd0098d686 100644 --- a/railties/guides/source/debugging_rails_applications.textile +++ b/railties/guides/source/debugging_rails_applications.textile @@ -247,9 +247,9 @@ If you see the message in the console or logs: Make sure you have started your web server with the option +--debugger+: -~/PathTo/rails_project$ script/server --debugger -=> Booting Mongrel (use 'script/server webrick' to force WEBrick) -=> Rails 2.2.0 application starting on http://0.0.0.0:3000 +~/PathTo/rails_project$ rails server --debugger +=> Booting Mongrel (use 'rails server webrick' to force WEBrick) +=> Rails 3.0.0 application starting on http://0.0.0.0:3000 => Debugger enabled ... @@ -472,10 +472,10 @@ class Author < ActiveRecord::Base end -TIP: You can use ruby-debug while using script/console. Just remember to +require "ruby-debug"+ before calling the +debugger+ method. +TIP: You can use ruby-debug while using +rails console+. Just remember to +require "ruby-debug"+ before calling the +debugger+ method. -/PathTo/project $ script/console +/PathTo/project $ rails console Loading development environment (Rails 2.1.0) >> require "ruby-debug" => [] @@ -636,7 +636,7 @@ require 'bleak_house' if ENV['BLEAK_HOUSE'] Start a server instance with BleakHouse integration: -RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house ./script/server +RAILS_ENV=production BLEAK_HOUSE=1 ruby-bleak-house rails server Make sure to run a couple hundred requests to get better data samples, then press +CTRL-C+. The server will stop and Bleak House will produce a dumpfile in +/tmp+: diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index fcd91f8956..4387fe3bd5 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -17,18 +17,18 @@ NOTE: This guide is about Rails generators for versions >= 3.0. Rails generators h3. First contact -When you create an application using the +rails+ command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking +script/generate+: +When you create an application using the +rails+ command, you are in fact using a Rails generator. After that, you can get a list of all available generators by just invoking +rails generate+: $ rails myapp $ cd myapp -$ ruby script/generate +$ rails generate You will get a list of all generators that comes with Rails. If you need a detailed description, for instance about the helper generator, you can simply do: -$ ruby script/generate helper --help +$ rails generate helper --help h3. Creating your first generator @@ -50,13 +50,13 @@ Our new generator is quite simple: it inherits from +Rails::Generators::Base+ an To invoke our new generator, we just need to do: -$ ruby script/generate initializer +$ rails generate initializer Before we go on, let's see our brand new generator description: -$ ruby script/generate initializer --help +$ rails generate initializer --help Rails usually is able to generate good descriptions if a generator is namespaced, as +ActiveRecord::Generators::ModelGenerator+, but not in this particular case. We can solve this problem in two ways. The first one is calling +desc+ inside our generator: @@ -77,7 +77,7 @@ h3. Creating generators with generators A faster way to create a generator is using the generator's generator: -$ ruby script/generate generator initializer +$ rails generate generator initializer create lib/generators/initializer create lib/generators/initializer/initializer_generator.rb create lib/generators/initializer/USAGE @@ -99,9 +99,9 @@ At first, we can notice that we are inheriting from +Rails::Generators::NamedBas We can see that by invoking the description of this new generator (don't forget to delete the old generator file): -$ ruby script/generate initializer --help +$ rails generate initializer --help Usage: - script/generate initializer NAME [options] + rails generate initializer NAME [options] We can also see in our new generator that it has a class method called +source_root+. This method points to where our generator templates will be placed and by default it points to the created directory under +RAILS_APP/lib/generators/initializer/templates+. In order to understand what a generator template means, let's create a file at +RAILS_APP/lib/generators/initializer/templates/initializer.rb+ with the following content: @@ -128,7 +128,7 @@ end And let's execute our generator: -$ ruby script/generate initializer foo +$ rails generate initializer foo We can see that now a initializer named foo was created at +config/initializers/foo.rb+ with the contents of our template. That means that copy_file copied a file in our source root to the destination path we gave. The method +file_name+ is automatically created when we inherit from +Rails::Generators::NamedBase+. @@ -166,7 +166,7 @@ end Before we customize our workflow, let's first see how our scaffold looks like: -$ ruby script/generate scaffold User name:string +$ rails generate scaffold User name:string invoke active_record create db/migrate/20091120125558_create_users.rb create app/models/user.rb @@ -212,7 +212,7 @@ If we generate another resource on scaffold, we can notice that neither styleshe To show that, we are going to create a new helper generator that simply adds some instance variable readers. First, we create a generator: -$ ruby script/generate generator my_helper +$ rails generate generator my_helper After that, we can delete both templates directory and the +source_root+ class method from our new generators, because we are not going to need them. So our new generator looks like the following: @@ -232,7 +232,7 @@ end We can try out our new generator by creating a helper for users: -$ ruby script/generate my_helper users +$ rails generate my_helper users And it will generate the following helper file in app/helpers: @@ -258,7 +258,7 @@ end And see it in action when invoking generator once again: -$ ruby script/generate scaffold Post body:text +$ rails generate scaffold Post body:text [...] invoke my_helper create app/helpers/posts_helper.rb @@ -343,7 +343,7 @@ Rails::Generators.fallbacks[:shoulda] = :test_unit Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators: -$ ruby script/generate scaffold Comment body:text +$ rails generate scaffold Comment body:text invoke active_record create db/migrate/20091120151323_create_comments.rb create app/models/comment.rb diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index bd6dbda199..a6ac7f0f5b 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -258,10 +258,10 @@ h3. Hello, Rails! One of the traditional places to start with a new language is by getting some text up on screen quickly. To do that in Rails, you need to create at minimum a controller and a view. Fortunately, you can do that in a single command. Enter this command in your terminal: -$ script/generate controller home index +$ rails generate controller home index -TIP: If you're on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails +script+ commands to Ruby: +ruby script/generate controller home index+. +TIP: If you're on Windows, or your Ruby is set up in some non-standard fashion, you may need to explicitly pass Rails +script+ commands to Ruby: +rails generate controller home index+. Rails will create several files for you, including +app/views/home/index.html.erb+. This is the template that will be used to display the results of the +index+ action (method) in the +home+ controller. Open this file in your text editor and edit it to contain a single line of code: @@ -274,7 +274,7 @@ h4. Starting up the Web Server You actually have a functional Rails application already - after running only two commands! To see it, you need to start a web server on your development machine. You can do this by running another command: -$ script/server +$ rails server This will fire up an instance of the Mongrel web server by default (Rails can also use several other web servers). To see your application in action, open a browser window and navigate to +http://localhost:3000+. You should see Rails' default information page: @@ -323,7 +323,7 @@ h3. Creating a Resource In the case of the blog application, you can start by generating a scaffolded Post resource: this will represent a single blog posting. To do this, enter this command in your terminal: -$ script/generate scaffold Post name:string title:string content:text +$ rails generate scaffold Post name:string title:string content:text NOTE. While scaffolding will get you up and running quickly, the "one size fits all" code that it generates is unlikely to be a perfect fit for your application. In most cases, you'll need to customize the generated code. Many experienced Rails developers avoid scaffolding entirely, preferring to write all or most of their source code from scratch. @@ -349,7 +349,7 @@ The scaffold generator will build 14 files in your application, along with some h4. Running a Migration -One of the products of the +script/generate scaffold+ command is a _database migration_. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created. +One of the products of the +rails generate scaffold+ command is a _database migration_. Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations, and it's possible to undo a migration after it's been applied to your database. Migration filenames include a timestamp to ensure that they're processed in the order that they were created. If you look in the +db/migrate/20090113124235_create_posts.rb+ file (remember, yours will have a slightly different name), here's what you'll find: @@ -400,7 +400,7 @@ Now you're ready to start working with posts. To do that, navigate to +http://lo !images/posts_index.png(Posts Index screenshot)! -This is the result of Rails rendering the +index+ view of your posts. There aren't currently any posts in the database, but if you click the +New Post+ link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single +script/generate scaffold+ command. +This is the result of Rails rendering the +index+ view of your posts. There aren't currently any posts in the database, but if you click the +New Post+ link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single +rails generate scaffold+ command. TIP: In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server. @@ -435,7 +435,7 @@ h4. Using the Console To see your validations in action, you can use the console. The console is a command-line tool that lets you execute Ruby code in the context of your application: -$ script/console +$ rails console After the console loads, you can use it to work with your application's models: @@ -516,7 +516,7 @@ 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 +script/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. 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: -$ script/generate model Comment commenter:string body:text +$ rails generate model Comment commenter:string body:text post:references @@ -953,7 +953,7 @@ h4. Generating a Controller With the model in hand, you can turn your attention to creating a matching controller. Again, there's a generator for this: -$ script/generate controller Comments index show new edit +$ rails generate controller Comments index show new edit This creates eight files: @@ -967,7 +967,7 @@ This creates eight files: * +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 -The controller will be generated with empty methods and views for each action that you specified in the call to +script/generate controller+: +The controller will be generated with empty methods and views for each action that you specified in the call to +rails generate controller+: class CommentsController < ApplicationController @@ -1052,7 +1052,7 @@ This creates a new +Comment+ object _and_ sets up the +post_id+ field to have th h4. Building Views -Because you skipped scaffolding, you'll need to build views for comments "by hand". Invoking +script/generate controller+ will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views. +Because you skipped scaffolding, you'll need to build views for comments "by hand". Invoking +rails generate controller+ will give you skeleton views, but they'll be devoid of actual content. Here's a first pass at fleshing out the comment views. The +views/comments/index.html.erb+ view: @@ -1214,7 +1214,7 @@ h3. Building a Multi-Model Form Comments and posts are edited on two separate forms - which makes sense, given the flow of this mini-application. But what if you want to edit more than one thing on a single form? Rails 2.3 offers new support for nested forms. Let's add support for giving each post multiple tags, right in the form where you create the post. First, create a new model to hold the tags: -$ script/generate model tag name:string post:references +$ rails generate model tag name:string post:references Run the migration to create the database table: diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 771c3e2523..558cbb4771 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -105,7 +105,7 @@ h4. Creating a Model The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want then statements for adding those will also be created. For example, running -ruby script/generate model Product name:string description:text +rails generate model Product name:string description:text will create a migration that looks like this @@ -135,7 +135,7 @@ h4. Creating a Standalone Migration If you are creating migrations for other purposes (for example to add a column to an existing table) then you can use the migration generator: -ruby script/generate migration AddPartNumberToProducts +rails generate migration AddPartNumberToProducts This will create an empty but appropriately named migration: @@ -153,7 +153,7 @@ end If the migration name is of the form "AddXXXToYYY" or "RemoveXXXFromYYY" and is followed by a list of column names and types then a migration containing the appropriate +add_column+ and +remove_column+ statements will be created. -ruby script/generate migration AddPartNumberToProducts part_number:string +rails generate migration AddPartNumberToProducts part_number:string will generate @@ -173,7 +173,7 @@ end Similarly, -ruby script/generate migration RemovePartNumberFromProducts part_number:string +rails generate migration RemovePartNumberFromProducts part_number:string generates @@ -193,7 +193,7 @@ end You are not limited to one magically generated column, for example -ruby script/generate migration AddDetailsToProducts part_number:string price:decimal +rails generate migration AddDetailsToProducts part_number:string price:decimal generates diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index f0dc9acbb8..5c760a5966 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -37,7 +37,7 @@ h4. Generating Performance Tests Rails provides a generator called +performance_test+ for creating new performance tests: -script/generate performance_test homepage +rails generate performance_test homepage This generates +homepage_test.rb+ in the +test/performance+ directory: @@ -381,19 +381,19 @@ h4. +benchmarker+ Usage: -$ script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ... +$ rails benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ... Examples: -$ script/performance/benchmarker 10 'Item.all' 'CouchItem.all' +$ rails benchmarker 10 'Item.all' 'CouchItem.all' If the +[times]+ argument is omitted, supplied methods are run just once: -$ script/performance/benchmarker 'Item.first' 'Item.last' +$ rails benchmarker 'Item.first' 'Item.last' h4. +profiler+ @@ -403,19 +403,19 @@ h4. +profiler+ Usage: -$ script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html] +$ rails profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html] Examples: -$ script/performance/profiler 'Item.all' +$ rails profiler 'Item.all' This will profile +Item.all+ in +RubyProf::WALL_TIME+ measure mode. By default, it prints flat output to the shell. -$ script/performance/profiler 'Item.all' 10 graph +$ rails profiler 'Item.all' 10 graph This will profile +10.times { Item.all }+ with +RubyProf::WALL_TIME+ measure mode and print graph output to the shell. @@ -423,7 +423,7 @@ This will profile +10.times { Item.all }+ with +RubyProf::WALL_TIME+ measure mod If you want to store the output in a file: -$ script/performance/profiler 'Item.all' 10 graph 2> graph.txt +$ rails profiler 'Item.all' 10 graph 2> graph.txt h3. Helper Methods diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index 06d0d493e4..71e1a7e3d3 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -39,9 +39,9 @@ The examples in this guide require that you have a working rails application. T gem install rails rails yaffle_guide cd yaffle_guide -script/generate scaffold bird name:string +rails generate scaffold bird name:string rake db:migrate -script/server +rails server Then navigate to http://localhost:3000/birds. Make sure you have a functioning rails app before continuing. @@ -57,16 +57,16 @@ This creates a plugin in 'vendor/plugins' including an 'init.rb' and 'README' as Examples:
-./script/generate plugin yaffle
-./script/generate plugin yaffle --with-generator
+rails generate plugin yaffle
+rails generate plugin yaffle --with-generator
 
-To get more detailed help on the plugin generator, type +./script/generate plugin+. +To get more detailed help on the plugin generator, type +rails generate plugin+. Later on this guide will describe how to work with generators, so go ahead and generate your plugin with the +--with-generator+ option now:
-./script/generate plugin yaffle --with-generator
+rails generate plugin yaffle --with-generator
 
You should see the following output: @@ -334,7 +334,7 @@ end To test that your method does what it says it does, run the unit tests with +rake+ from your plugin directory. To see this in action, fire up a console and start squawking: -$ ./script/console +$ rails console >> "Hello World".to_squawk => "squawk! Hello World" @@ -871,7 +871,7 @@ If you plan to distribute your plugin, developers will expect at least a minimum Rails ships with several built-in generators. You can see all of the generators available to you by typing the following at the command line: -./script/generate +rails generate You should see something like this: @@ -882,7 +882,7 @@ Installed Generators Builtin: controller, integration_test, mailer, migration, model, observer, plugin, resource, scaffold, session_migration
-When you run +script/generate yaffle_definition -h+ you should see the contents of your 'vendor/plugins/yaffle/generators/yaffle_definition/USAGE'. +When you run +rails generate yaffle_definition -h+ you should see the contents of your 'vendor/plugins/yaffle/generators/yaffle_definition/USAGE'. For this plugin, update the USAGE file could look like this: @@ -1111,11 +1111,11 @@ end To see this work, type: -./script/generate yaffle_route -./script/destroy yaffle_route +rails generate yaffle_route +rails destroy yaffle_route -NOTE: If you haven't set up the custom route from above, 'script/destroy' will fail and you'll have to remove it manually. +NOTE: If you haven't set up the custom route from above, 'rails destroy' will fail and you'll have to remove it manually. h3. Migrations @@ -1195,7 +1195,7 @@ h4. Generate Migrations Generating migrations has several advantages over other methods. Namely, you can allow other developers to more easily customize the migration. The flow looks like this: - * call your script/generate script and pass in whatever options they need + * call your rails generate script and pass in whatever options they need * examine the generated migration, adding/removing columns or other options as necessary This example will demonstrate how to use one of the built-in generator methods named 'migration_template' to create a migration file. Extending the rails migration generator requires a somewhat intimate knowledge of the migration generator internals, so it's best to write a test first: @@ -1289,7 +1289,7 @@ It's courteous to check to see if table names are being pluralized whenever you To run the generator, type the following at the command line: -./script/generate yaffle_migration bird +rails generate yaffle_migration bird and you will see a new file: diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index df93580e89..eef44d9ec9 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -30,11 +30,11 @@ h4. Rails Application's Rack Object ActionController::Dispatcher.new is the primary Rack application object of a Rails application. Any Rack compliant web server should be using +ActionController::Dispatcher.new+ object to serve a Rails application.

-h4. +script/server+ +h4. +rails server+ -script/server does the basic job of creating a +Rack::Builder+ object and starting the webserver. This is Rails' equivalent of Rack's +rackup+ script. +rails server does the basic job of creating a +Rack::Builder+ object and starting the webserver. This is Rails' equivalent of Rack's +rackup+ script. -Here's how +script/server+ creates an instance of +Rack::Builder+ +Here's how +rails server+ creates an instance of +Rack::Builder+ app = Rack::Builder.new { @@ -54,7 +54,7 @@ Middlewares used in the code above are primarily useful only in the development h4. +rackup+ -To use +rackup+ instead of Rails' +script/server+, you can put the following inside +config.ru+ of your Rails application's root directory: +To use +rackup+ instead of Rails' +rails server+, you can put the following inside +config.ru+ of your Rails application's root directory: # RAILS_ROOT/config.ru @@ -233,7 +233,7 @@ h4. Generating a Metal Application Rails provides a generator called +metal+ for creating a new Metal application: -$ script/generate metal poller +$ rails generate metal poller This generates +poller.rb+ in the +app/metal+ directory: diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index c7b475899f..ac9fb4276e 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -56,7 +56,7 @@ h5. What are Fixtures? _Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: *YAML* or *CSV*. In this guide we will use *YAML* which is the preferred format. -You'll find fixtures under your +test/fixtures+ directory. When you run +script/generate model+ to create a new model, fixture stubs will be automatically created and placed in this directory. +You'll find fixtures under your +test/fixtures+ directory. When you run +rails generate model+ to create a new model, fixture stubs will be automatically created and placed in this directory. h5. YAML @@ -144,10 +144,10 @@ For this guide we will be using Rails _scaffolding_. It will create the model, a NOTE: For more information on Rails _scaffolding_, refer to "Getting Started with Rails":getting_started.html -When you use +script/generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder: +When you use +rails generate scaffold+, for a resource among other things it creates a test stub in the +test/unit+ folder:
-$ script/generate scaffold post title:string body:text
+$ rails generate scaffold post title:string body:text
 ...
 create  app/models/post.rb
 create  test/unit/post_test.rb
@@ -604,7 +604,7 @@ Integration tests are used to test the interaction among any number of controlle
 Unlike Unit and Functional tests, integration tests have to be explicitly created under the 'test/integration' folder within your application. Rails provides a generator to create an integration test skeleton for you.
 
 
-$ script/generate integration_test user_flows
+$ rails generate integration_test user_flows
       exists  test/integration/
       create  test/integration/user_flows_test.rb
 
-- 
cgit v1.2.3


From d6ae930c9cfacf50d65b2880ac21efe80801a33d Mon Sep 17 00:00:00 2001
From: RomD 
Date: Sun, 7 Feb 2010 04:56:19 +0100
Subject: fix ambiguous example for new invocation method
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: José Valim 
---
 railties/guides/source/3_0_release_notes.textile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'railties/guides')

diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 1624172176..639e775bf5 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -39,8 +39,8 @@ h4. script/* replaced by script/rails
 The new script/rails replaces all the scripts that used to be in the script directory. You do not run script/rails directly though, the +rails+ command detects it is being invoked in the root of a Rails application and runs the script for you. Intended usage is:
 
 
-rails console                      # => ./script/rails console
-rails g scaffold post title:string # => ./script/rails generate scaffold post title:string
+rails console                      # instead of script/console
+rails g scaffold post title:string # instead of script/generate scaffold post title:string
 
 
 Run rails --help for a list of all the options.
-- 
cgit v1.2.3


From 783ce11708a63a6a015dd07e6ab0e79a5f98af8f Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Wed, 10 Feb 2010 10:03:41 +0100
Subject: release notes: the following methods have resurrected:
 Class#reachable?, Object#subclasses_of, Class#subclasses, Class.subclasses_of

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 7b85e90238..7e4d6ed067 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -529,8 +529,8 @@ The security patch for REXML remains in Active Support because early patchlevels
 The following methods have been removed because they are no longer used in the framework:
 
 * +Kernel#daemonize+
-* Object#remove_subclasses_of, Object#subclasses_of, Object#extend_with_included_modules_from, Object#extended_by
-* Class#subclasses, Class#reachable?, Class#remove_class
+* Object#remove_subclasses_of Object#extend_with_included_modules_from, Object#extended_by
+* Class#remove_class
 * Regexp#number_of_captures, Regexp.unoptionalize, Regexp.optionalize, Regexp#number_of_captures
 
 
-- 
cgit v1.2.3


From 6a395c68d20bf72db826c53d5f44b3bde5069699 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Thu, 11 Feb 2010 00:03:55 +0100
Subject: AS guide: documents Object#subclasses_of

---
 .../source/active_support_core_extensions.textile  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 2d05e66307..da22b4113d 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -323,6 +323,40 @@ TIP: Since +with_options+ forwards calls to its receiver they can be nested. Eac
 
 NOTE: Defined in +active_support/core_ext/object/with_options.rb+.
 
+h5. +subclasses_of+
+
+The method +subclasses_of+ receives an arbitrary number of class objects and returns all their anonymous or reachable descendants as a single array:
+
+
+class C; end
+subclasses_of(C) # => []
+
+subclasses_of(Integer) # => [Bignum, Fixnum]
+
+module M
+  class A; end
+  class B1 < A; end
+  class B2 < A; end
+end
+
+module N
+  class C < M::B1; end
+end
+
+subclasses_of(M::A) # => [N::C, M::B2, M::B1]
+
+
+The order in which these classes are returned is unspecified. The returned collection may have duplicates:
+
+
+subclasses_of(Numeric, Integer)
+# => [Bignum, Float, Fixnum, Integer, Date::Infinity, Rational, BigDecimal, Bignum, Fixnum]
+
+
+See also +Class#subclasses+ in "Extensions to +Class+ FIX THIS LINK":FIXME.
+
+NOTE: Defined in +active_support/core_ext/object/extending.rb+.
+
 h4. Instance Variables
 
 Active Support provides several methods to ease access to instance variables.
-- 
cgit v1.2.3


From 72c83893a5221c1054347bda2be09ee4b7f3a897 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Thu, 11 Feb 2010 00:20:37 +0100
Subject: AS guide: documents Class#subclasses

---
 .../source/active_support_core_extensions.textile  | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index da22b4113d..f58bed54d7 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -977,6 +977,39 @@ If for whatever reason an application loads the definition of a mailer class and
 
 NOTE: Defined in +active_support/core_ext/class/delegating_attributes.rb+.
 
+h4. Descendants
+
+h5. +subclasses+
+
+The +subclasses+ method returns the names of all the anonymous or reachable descendants of its receiver as an array of strings:
+
+
+class C; end
+C.subclasses # => []
+
+Integer.subclasses # => ["Bignum", "Fixnum"]
+
+module M
+  class A; end
+  class B1 < A; end
+  class B2 < A; end
+end
+
+module N
+  class C < M::B1; end
+end
+
+M::A.subclasses # => ["N::C", "M::B2", "M::B1"]
+
+
+The order in which these class names are returned is unspecified.
+
+See also +Object#subclasses_of+ in "Extensions to All Objects FIX THIS LINK":FIXME.
+
+WARNING: This method is redefined in some Rails core classes.
+
+NOTE: Defined in +active_support/core_ext/class/subclasses.rb+.
+
 h3. Extensions to +String+
 
 h4. Output Safety
-- 
cgit v1.2.3


From 739b8a1638e1a6b40a906cca926764e1aad1d127 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Thu, 11 Feb 2010 00:22:13 +0100
Subject: AS guide: fixes a typo

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index f58bed54d7..3890341d13 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -375,7 +375,7 @@ end
 C.new(0, 1).instance_variable_names # => ["@y", "@x"]
 
 
-WARNING: The order in which the names are returned is unespecified, and it indeed depends on the version of the interpreter.
+WARNING: The order in which the names are returned is unspecified, and it indeed depends on the version of the interpreter.
 
 NOTE: Defined in +active_support/core_ext/object/instance_variables.rb+.
 
-- 
cgit v1.2.3


From 50b2a5d8cac95ac07979518478d2c4d37f33458a Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 12 Feb 2010 19:06:07 +0100
Subject: AS guide: documents Module#reachable?

---
 .../source/active_support_core_extensions.textile  | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 3890341d13..7af89a6d24 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -849,6 +849,44 @@ The method receives the name of an action, and a +:with+ option with code. The c
 
 NOTE: Defined in +active_support/core_ext/module/synchronization.rb+.
 
+h4. Reachable Modules
+
+A named module is reachable if it is stored in its correspoding constant. It means you can reach the module object via the constant.
+
+That is what ordinarily happens, if a module is called "M", the +M+ constant exists and holds it:
+
+
+module M
+end
+
+M.reachable? # => true
+
+
+But since constants and modules are indeed kind of decoupled, module objects can become unreachable:
+
+
+module M
+end
+
+orphan = Object.send(:remove_const, :M)
+
+# The module object is orphan now but it still has a name.
+orphan.name # => "M"
+
+# You cannot reach it via the constant M because it does not even exist.
+orphan.reachable? # => false
+
+# Let's define a module called "M" again.
+module M
+end
+
+# The constant M exists now again, and it stores a module
+# object called "M", but it is a new instance.
+orphan.reachable? # => false
+
+
+NOTE: Defined in +active_support/core_ext/module/reachable.rb+.
+
 h3. Extensions to +Class+
 
 h4. Class Attributes
-- 
cgit v1.2.3


From 77bf78b3b78a41d4f2f6e733f5c9c00608c0adba Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 12 Feb 2010 20:52:00 +0100
Subject: AS guide: documents Module#anonymous?

---
 .../source/active_support_core_extensions.textile  | 43 +++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 7af89a6d24..ce87919b89 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -849,7 +849,7 @@ The method receives the name of an action, and a +:with+ option with code. The c
 
 NOTE: Defined in +active_support/core_ext/module/synchronization.rb+.
 
-h4. Reachable Modules
+h4. Reachable
 
 A named module is reachable if it is stored in its correspoding constant. It means you can reach the module object via the constant.
 
@@ -887,6 +887,47 @@ orphan.reachable? # => false
 
 NOTE: Defined in +active_support/core_ext/module/reachable.rb+.
 
+h4. Anonymous
+
+A module may or may not have a name:
+
+
+module M
+end
+M.name # => "M"
+
+N = Module.new
+N.name # => "N"
+
+Module.new.name # => "" in 1.8, nil in 1.9
+
+
+You can check whether a module has a name with the predicate +anonymous?+:
+
+
+module M
+end
+M.anonymous? # => false
+
+Module.new.anonymous? # => true
+
+
+Note that being unreachable does not imply being anonymous:
+
+
+module M
+end
+
+m = Object.send(:remove_const, :M)
+
+m.reachable? # => false
+m.anonymous? # => false
+
+
+though an anonymous module is unreachable by definition.
+
+NOTE: Defined in +active_support/core_ext/module/anonymous.rb+.
+
 h3. Extensions to +Class+
 
 h4. Class Attributes
-- 
cgit v1.2.3


From f3eab8e6639db77ba414ea3b0bf17c94cadecba9 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Wed, 17 Feb 2010 20:22:37 +0100
Subject: adds support for an edge badge in guides

---
 railties/guides/images/edge_badge.png     | Bin 0 -> 9095 bytes
 railties/guides/rails_guides/generator.rb |  11 +++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 railties/guides/images/edge_badge.png

(limited to 'railties/guides')

diff --git a/railties/guides/images/edge_badge.png b/railties/guides/images/edge_badge.png
new file mode 100644
index 0000000000..274801bb71
Binary files /dev/null and b/railties/guides/images/edge_badge.png differ
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index b931dd6c28..2f0718af75 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -49,16 +49,19 @@ module RailsGuides
         if guide =~ /\.textile\.erb$/
           # Generate the erb pages with textile formatting - e.g. index/authors
           result = view.render(:layout => 'layout', :file => guide)
-          f.write textile(result)
+          result = textile(result)
         else
           body = File.read(File.join(view_path, guide))
           body = set_header_section(body, @view)
           body = set_index(body, @view)
 
           result = view.render(:layout => 'layout', :text => textile(body).html_safe)
-          f.write result
+
           warn_about_broken_links(result) if ENV.key?("WARN_BROKEN_LINKS")
         end
+        
+        result = insert_edge_badge(result) if ENV.key?('INSERT_EDGE_BADGE')
+        f.write result
       end
     end
 
@@ -168,5 +171,9 @@ module RailsGuides
         end
       end
     end
+    
+    def insert_edge_badge(html)
+      html.sub(/]*>/, '\&')
+    end
   end
 end
-- 
cgit v1.2.3


From 217ffcb50829cef86623d365bbf06135c52de9e8 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Wed, 17 Feb 2010 21:08:31 +0100
Subject: edge badge revised by Jose Espinal

---
 railties/guides/images/edge_badge.png | Bin 9095 -> 7945 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)

(limited to 'railties/guides')

diff --git a/railties/guides/images/edge_badge.png b/railties/guides/images/edge_badge.png
index 274801bb71..cddd46c4b8 100644
Binary files a/railties/guides/images/edge_badge.png and b/railties/guides/images/edge_badge.png differ
-- 
cgit v1.2.3


From d2844b854b57e2e3c8693c796e7296e45a866212 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 19 Feb 2010 20:22:20 +0100
Subject: AM guide: standarizes call to rails runner

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index 941c2e9771..d6a5e6aeb8 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -333,7 +333,7 @@ Receiving and parsing emails with Action Mailer can be a rather complex endeavou
 
 * Implement a +receive+ method in your mailer.
 
-* Configure your email server to forward emails from the address(es) you would like your app to receive to +/path/to/app/script/rails runner 'UserMailer.receive(STDIN.read)'+.
+* Configure your email server to forward emails from the address(es) you would like your app to receive to +rails runner 'UserMailer.receive(STDIN.read)'+.
 
 Once a method called +receive+ is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer +receive+ instance method. Here's an example:
 
-- 
cgit v1.2.3


From 4bd37dadc45ac616117c9cf2b4fbb4c8f890226b Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 19 Feb 2010 20:27:24 +0100
Subject: getting started guide: script/generate -> rails generate

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 8ddf0cf3cf..ad328c6b51 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -431,7 +431,7 @@ Now you're ready to start working with posts. To do that, navigate to "http://lo
 
 !images/posts_index.png(Posts Index screenshot)!
 
-This is the result of Rails rendering the +index+ view of your posts. There aren't currently any posts in the database, but if you click the +New Post+ link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single +script/generate scaffold+ command.
+This is the result of Rails rendering the +index+ view of your posts. There aren't currently any posts in the database, but if you click the +New Post+ link you can create one. After that, you'll find that you can edit posts, look at their details, or destroy them. All of the logic and HTML to handle this was built by the single +rails generate scaffold+ command.
 
 TIP: In development mode (which is what you're working in by default), Rails reloads your application with every browser request, so there's no need to stop and restart the web server.
 
-- 
cgit v1.2.3


From 17596beb894dfdf8da1dc338a452176d1c58cf38 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 19 Feb 2010 20:30:46 +0100
Subject: Revert "AM guide: standarizes call to rails runner"

This reverts commit d2844b854b57e2e3c8693c796e7296e45a866212.
---
 railties/guides/source/action_mailer_basics.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides')

diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index d6a5e6aeb8..941c2e9771 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -333,7 +333,7 @@ Receiving and parsing emails with Action Mailer can be a rather complex endeavou
 
 * Implement a +receive+ method in your mailer.
 
-* Configure your email server to forward emails from the address(es) you would like your app to receive to +rails runner 'UserMailer.receive(STDIN.read)'+.
+* Configure your email server to forward emails from the address(es) you would like your app to receive to +/path/to/app/script/rails runner 'UserMailer.receive(STDIN.read)'+.
 
 Once a method called +receive+ is defined in any mailer, Action Mailer will parse the raw incoming email into an email object, decode it, instantiate a new mailer, and pass the email object to the mailer +receive+ instance method. Here's an example:
 
-- 
cgit v1.2.3


From cadd5937fe186abf3b4b0964aa9d2d53ae4b609b Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Wed, 24 Feb 2010 00:56:51 +0100
Subject: plugins guide: rewords a paragraph and revises some typography

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index 71e1a7e3d3..95b06c41a0 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -1333,15 +1333,15 @@ yaffle:squawk             # Prints out the word 'Yaffle'
 
 You can add as many files as you want in the tasks directory, and if they end in .rake Rails will pick them up.
 
-Note that tasks from 'vendor/plugins/yaffle/Rakefile' are not available to the main app.
+Note that tasks from +vendor/plugins/yaffle/Rakefile+ are not available to the main app.
 
-h3. PluginGems
+h3. Plugins as Gems
 
 Turning your rails plugin into a gem is a simple and straightforward task.  This section will cover how to turn your plugin into a gem.  It will not cover how to distribute that gem.
 
-Historically rails plugins loaded the plugin's 'init.rb' file.  In fact some plugins contain all of their code in that one file.  To be compatible with plugins, 'init.rb' was moved to 'rails/init.rb'.
+The initialization file has to be called +rails/init.rb+, the root +init.rb+ file, if any, is ignored by Rails. Also, the name of the plugin now is relevant since +config.gem+ tries to load it. Either name the main file after your gem, or document that users should use the +:lib+ option.
 
-It's common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in 'Rakefile'.  A rake task that packages the gem might look like this:
+It's common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in +Rakefile+.  A rake task that packages the gem might look like this:
 
 * *vendor/plugins/yaffle/Rakefile:*
 
@@ -1383,7 +1383,7 @@ rake gem
 sudo gem install pkg/yaffle-0.0.1.gem
 
 
-To test this, create a new rails app, add 'config.gem "yaffle"' to environment.rb and all of your plugin's functionality will be available to you.
+To test this, create a new rails app, add +config.gem "yaffle"+ to +config/environment.rb+ and all of your plugin's functionality will be available to you.
 
 h3. RDoc Documentation
 
-- 
cgit v1.2.3


From 47683b7d0ec5489aa01d1526c1b147528eca6170 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Wed, 24 Feb 2010 01:34:04 +0100
Subject: caching guide: fixes a typo, thanks to Jonathan Bryan

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile
index ac6f944457..e27c2a6dc6 100644
--- a/railties/guides/source/caching_with_rails.textile
+++ b/railties/guides/source/caching_with_rails.textile
@@ -152,7 +152,7 @@ expire_fragment('all_available_products')
 
 h4. Sweepers
 
-Cache sweeping is a mechanism which allows you to get around having a ton of +expire_{page,action,fragment}+ calls in your code.  It does this by moving all the work required to expire cached content into a +ActionController::Caching::Sweeper+ class.  This class is an Observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object in an around or after filter.
+Cache sweeping is a mechanism which allows you to get around having a ton of +expire_{page,action,fragment}+ calls in your code.  It does this by moving all the work required to expire cached content into an +ActionController::Caching::Sweeper+ subclass.  This class is an observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object in an around or after filter.
 
 Continuing with our Product controller example, we could rewrite it with a sweeper like this:
 
-- 
cgit v1.2.3


From 4dcc4a0b60fbcca0395ac94b62147e2f9567a425 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Fri, 26 Feb 2010 00:06:05 +0100
Subject: AS guide: s/metaclass/singleton_class/ due to 0b87d11

---
 .../guides/source/active_support_core_extensions.textile  | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

(limited to 'railties/guides')

diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index ce87919b89..278d27ec67 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -138,16 +138,19 @@ end
 
 NOTE: Defined in +active_support/core_ext/object/try.rb+.
 
-h4. +metaclass+
+h4. +singleton_class+
 
-The method +metaclass+ returns the singleton class on any object:
+The method +singleton_class+ returns the singleton class of the receiver:
 
 
-String.metaclass     # => #
-String.new.metaclass # => #>
+String.singleton_class     # => #
+String.new.singleton_class # => #>
 
 
-NOTE: Defined in +active_support/core_ext/object/metaclass.rb+.
+WARNING: Fixnums and symbols have no singleton classes, +singleton_class+
+raises +TypeError+ on them.
+
+NOTE: Defined in +active_support/core_ext/object/singleton_class.rb+.
 
 h4. +class_eval(*args, &block)+
 
@@ -168,7 +171,7 @@ class Proc
 end
 
 
-NOTE: Defined in +active_support/core_ext/object/metaclass.rb+.
+NOTE: Defined in +active_support/core_ext/object/singleton_class.rb+.
 
 h4. +acts_like?(duck)+
 
-- 
cgit v1.2.3


From 56c162e75dff480ad90c8fed47a4fa3d41e411db Mon Sep 17 00:00:00 2001
From: Ryan Bigg 
Date: Sun, 28 Feb 2010 09:42:06 +1100
Subject: Fix validates_exclusion_of error message as per http://bit.ly/9kxANI
 [gmile]

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

(limited to 'railties/guides')

diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile
index dc61021f76..83c85402ec 100644
--- a/railties/guides/source/activerecord_validations_callbacks.textile
+++ b/railties/guides/source/activerecord_validations_callbacks.textile
@@ -240,7 +240,7 @@ end
 
 The +validates_exclusion_of+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+  that you can use for the same purpose, if you'd like to. This example uses the +:message+ option to show how you can include the attribute's value.
 
-The default error message for +validates_exclusion_of+  is "_is not included in the list_".
+The default error message for +validates_exclusion_of+  is "_is reserved_".
 
 h4. +validates_format_of+
 
-- 
cgit v1.2.3


From f3a7f0e028c72ed5e38e3eed9369d339addd3c19 Mon Sep 17 00:00:00 2001
From: Xavier Noria 
Date: Sun, 28 Feb 2010 00:14:48 +0100
Subject: plugins guide: rails/init.rb is deprecated

---
 railties/guides/source/plugins.textile | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

(limited to 'railties/guides')

diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index 95b06c41a0..2db421aa91 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -104,7 +104,7 @@ To make it easy to organize your files and to make the plugin more compatible wi
     `-- init.rb
 
-*vendor/plugins/yaffle/rails/init.rb* +*vendor/plugins/yaffle/init.rb* require 'yaffle' @@ -341,13 +341,15 @@ $ rails console h4. Working with +init.rb+ -When rails loads plugins it looks for the file named 'init.rb' or 'rails/init.rb'. However, when the plugin is initialized, 'init.rb' is invoked via +eval+ (not +require+) so it has slightly different behavior. +When Rails loads plugins it looks for a file named +init.rb+. However, when the plugin is initialized, +init.rb+ is invoked via +eval+ (not +require+) so it has slightly different behavior. -Under certain circumstances if you reopen classes or modules in 'init.rb' you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from +init.rb+, as shown above. +NOTE: The plugins loader also looks for +rails/init.rb+, but that one is deprecated in favor of the top-level +init.rb+ aforementioned. + +Under certain circumstances if you reopen classes or modules in +init.rb+ you may inadvertently create a new class, rather than reopening an existing class. A better alternative is to reopen the class in a different file, and require that file from +init.rb+, as shown above. If you must reopen a class in +init.rb+ you can use +module_eval+ or +class_eval+ to avoid any issues: -* *vendor/plugins/yaffle/rails/init.rb* +* *vendor/plugins/yaffle/init.rb* Hash.class_eval do @@ -359,7 +361,7 @@ end Another way is to explicitly define the top-level module space for all modules and classes, like +::Hash+: -* *vendor/plugins/yaffle/rails/init.rb* +* *vendor/plugins/yaffle/init.rb* class ::Hash -- cgit v1.2.3 From 68dd44cc62062c8f3c82dde678bf99e8f2245bb5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Feb 2010 22:28:58 +0100 Subject: AS guide: documents String#pluralize --- .../guides/source/active_support_core_extensions.textile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 278d27ec67..b3e4bc778a 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1249,6 +1249,22 @@ The call +str.last(n)+ is equivalent to +str.from(-n)+ if +n+ > 0, and returns a NOTE: Defined in +active_support/core_ext/string/access.rb+. +h4. Inflections + +h5. +pluralize+ + +The method +pluralize+ returns the plural of its receiver: + + +"table".pluralize # => "tables" +"ruby".pluralize # => "rubies" +"equipment".pluralize # => "equipment" + + +As the previous example shows, Active Support knows some irregular plurals and a few uncountable nouns. Builtin rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 947511e50e7c60d8bed581c8f20f4ebbc72a4d14 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 28 Feb 2010 22:32:00 +0100 Subject: AS guide: shortens a sentence --- railties/guides/source/active_support_core_extensions.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b3e4bc778a..23879827e2 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1261,7 +1261,7 @@ The method +pluralize+ returns the plural of its receiver: "equipment".pluralize # => "equipment" -As the previous example shows, Active Support knows some irregular plurals and a few uncountable nouns. Builtin rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments. +As the previous example shows, Active Support knows some irregular plurals and uncountable nouns. Builtin rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments. NOTE: Defined in +active_support/core_ext/string/inflections.rb+. -- cgit v1.2.3 From 51e84bfbd6e53cef8b563bdf99ea47631bece677 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 05:35:01 +0100 Subject: AS guide: adds a real example for #pluralize --- railties/guides/source/active_support_core_extensions.textile | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 23879827e2..7ee414f34b 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1263,6 +1263,17 @@ The method +pluralize+ returns the plural of its receiver: As the previous example shows, Active Support knows some irregular plurals and uncountable nouns. Builtin rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments. +Active Record uses this method to compute the default table name that corresponds to a model: + + +# active_record/base.rb +def undecorated_table_name(class_name = base_class.name) + table_name = class_name.to_s.demodulize.underscore + table_name = table_name.pluralize if pluralize_table_names + table_name +end + + NOTE: Defined in +active_support/core_ext/string/inflections.rb+. h3. Extensions to +Numeric+ -- cgit v1.2.3 From 1064c533ceb46562da39b3b0e50709ceaf0d65d4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 05:43:56 +0100 Subject: AS guide: documents String#singularize --- .../source/active_support_core_extensions.textile | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 7ee414f34b..c1a79189bd 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1276,6 +1276,29 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +singularize+ + +The inverse of +pluralize+: + + +"tables".singularize # => "table" +"rubies".singularize # => "ruby" +"equipment".singularize # => "equipment" + + +Associations compute the name of the corresponding default associated class using this method: + + +# active_record/reflection.rb +def derive_class_name + class_name = name.to_s.camelize + class_name = class_name.singularize if collection? + class_name +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 0f847b95ebe2d80bfe67d4f182a4458f2091f322 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 06:07:31 +0100 Subject: AS guide: documents String#underscore --- .../source/active_support_core_extensions.textile | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index c1a79189bd..51ef164d85 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1299,6 +1299,85 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +camelize+ + +The method +camelize+ returns its receiver in camel case: + + +"product".camelize # => "Product" +"admin_user".camelize # => "AdminUser" + + +As a rule of thumb you can think of this method as the one that transforms paths into Ruby class or module names, where slashes separate namespaces: + + +"backoffice/session".camelize # => "Backoffice::Session" + + +For example, Action Pack uses this method to load the class that provides a certain session store: + + +# action_controller/metal/session_management.rb +def session_store=(store) + if store == :active_record_store + self.session_store = ActiveRecord::SessionStore + else + @@session_store = store.is_a?(Symbol) ? + ActionDispatch::Session.const_get(store.to_s.camelize) : + store + end +end + + ++camelize+ accepts an optional argument, it can be +:upper+ (default), or +:lower+. With the latter the first letter becomes lowercase: + + +"visual_effect".camelize(:lower) # => "visualEffect" + + +That may be handy to compute method names in a language that follows that convention, for example JavaScript. + ++camelize+ is aliased to +camelcase+. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + +h5. +underscore+ + +The method +underscore+ is the inverse of +camelize+, explained above: + + +"Product".underscore # => "product" +"AdminUser".underscore # => "admin_user" + + +Also converts "::" back to "/": + + +"Backoffice::Session".underscore # => "backoffice/session" + + +and understands strings that start with lowercase: + + +"visualEffect".underscore # => "visual_effect" + + ++underscore+ accepts no argument though. + +Rails class and module autoloading uses +underscore+ to infer the relative path without extension of a file that would define a given missing constant: + + +# active_support/dependencies.rb +def load_missing_constant(from_mod, const_name) + ... + qualified_name = qualified_name_for from_mod, const_name + path_suffix = qualified_name.underscore + ... +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From aed8c1f0a471915bc10cf8be3244f4efa69f06b5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 22:17:12 +0100 Subject: AV guide: titleize is defined by Active Support --- railties/guides/source/action_view_overview.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index 4aa43a8f3c..a517193cea 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -33,13 +33,13 @@ gem install actionpack gem install rack
-Now we'll create a simple "Hello World" application that uses the +titleize+ method provided by Action View. +Now we'll create a simple "Hello World" application that uses the +titleize+ method provided by Active Support. *hello_world.rb:* require 'rubygems' -require 'action_view' +require 'active_support/core_ext/string/inflections' require 'rack' def hello_world(env) -- cgit v1.2.3 From 71990a4157f37bc7529184654265679a62a9e121 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 22:32:58 +0100 Subject: AS guide: documents String#titleize --- .../guides/source/active_support_core_extensions.textile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 51ef164d85..5f1849f2b6 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1378,6 +1378,19 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +titleize+ + +The method +titleize+ capitalizes the words in the receiver: + + +"alice in wonderland".titleize # => "Alice In Wonderland" +"fermat's enigma".titleize # => "Fermat's Enigma" + + ++titleize+ is aliased to +titlecase+. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 44bd3bd4ff2705b798313fbbb60cb7064b328f9b Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 22:58:21 +0100 Subject: AS guide: documents String#dasherize --- .../source/active_support_core_extensions.textile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 5f1849f2b6..e56dde2977 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1391,6 +1391,27 @@ The method +titleize+ capitalizes the words in the receiver: NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +dasherize+ + +The method +dasherize+ replaces the underscores in the receiver with dashes: + + +"name".dasherize # => "name" +"contact_data".dasherize # => "contact-data" + + +The XML serializer of models uses this method to dasherize node names: + + +# active_model/serializers/xml.rb +def reformat_name(name) + name = name.camelize if camelize? + dasherize? ? name.dasherize : name +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From aab42ccdab084dbd661d3e21d9fce15d0f3f6a06 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 1 Mar 2010 23:42:12 +0100 Subject: AS guide: documents String#demodulize --- .../source/active_support_core_extensions.textile | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index e56dde2977..307f7eddb3 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1412,6 +1412,31 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +demodulize+ + +Given a string with a qualified constant reference expression, +demodulize+ returns the very constant name, that is, the rightmost part of it: + + +"Product".demodulize # => "Product" +"Backoffice::UsersController".demodulize # => "UsersController" +"Admin::Hotel::ReservationUtils".demodulize # => "ReservationUtils" + + +Active Record for example uses this method to compute the name of a counter cache column: + + +# active_record/reflection.rb +def counter_cache_column + if options[:counter_cache] == true + "#{active_record.name.demodulize.underscore.pluralize}_count" + elsif options[:counter_cache] + options[:counter_cache] + end +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From fbce2327a9d327a203bb401708b6e3a4bd023e38 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 2 Mar 2010 00:06:32 +0100 Subject: AS guide: documents String#parameterize --- .../guides/source/active_support_core_extensions.textile | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 307f7eddb3..291dc5e96a 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1437,6 +1437,19 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +parameterize+ + +The method +parameterize+ normalizes its receiver in a way that can be used in pretty URLs. + + +"John Smith".parameterize # => "john-smith" +"Kurt Gödel".parameterize # => "kurt-godel" + + +In fact, the result string is wrapped in an instance of +ActiveSupport::Multibyte::Chars+. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 88c01b3f10d8bc47359f2f69f69a606ace5fc0f6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 2 Mar 2010 00:25:25 +0100 Subject: AS guide: documents String#tableize --- .../guides/source/active_support_core_extensions.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 291dc5e96a..2571c83dd8 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1450,6 +1450,20 @@ In fact, the result string is wrapped in an instance of +ActiveSupport::Multibyt NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +tableize+ + +The method +tableize+ is +underscore+ followed by +pluralize+. + + +"Person".tableize # => "people" +"Invoice".tableize # => "invoices" +"InvoiceLine".tableize # => "invoice_lines" + + +As a rule of thumb, +tableize+ returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight +tableize+ indeed, because it also demodulizes de class name and checks a few options that may affect the returned string. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 3084898ca6d98d37da64705d755e189e36040339 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 2 Mar 2010 22:29:58 +0100 Subject: AS guide: documents String#classify --- .../source/active_support_core_extensions.textile | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 2571c83dd8..26e4113edf 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1457,13 +1457,33 @@ The method +tableize+ is +underscore+ followed by +pluralize+. "Person".tableize # => "people" "Invoice".tableize # => "invoices" -"InvoiceLine".tableize # => "invoice_lines" +"InvoiceLine".tableize # => "invoice_lines" As a rule of thumb, +tableize+ returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight +tableize+ indeed, because it also demodulizes de class name and checks a few options that may affect the returned string. NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +classify+ + +The method +classify+ is the inverse of +tableize+. It gives you the class name corresponding to a table name: + + +"people".classify # => "Person" +"invoices".classify # => "Invoice" +"invoice_lines".classify # => "InvoiceLine" + + +The method understands qualified table names: + + +"highrise_production.companies".classify # => "Company" + + +Note that +classify+ returns a class name as a string. You can get the actual class object invoking +constantize+ on it, explained next. + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 8627281e3b75dbafc0adee7ab4f3d28a177aa9e5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 2 Mar 2010 23:02:44 +0100 Subject: AS guide: documents String#constantize --- .../source/active_support_core_extensions.textile | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 26e4113edf..149ebefbab 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1484,6 +1484,49 @@ Note that +classify+ returns a class name as a string. You can get the actual cl NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +constantize+ + +The method +constantize+ resolves the constant reference expression in its receiver: + + +"Fixnum".constantize # => Fixnum + +module M + X = 1 +end +"M::X".constantize # => 1 + + +If the string evaluates to no known constant, or its content is not even a valid constant name, +constantize+ raises +NameError+. + +Constant name resolution by +constantize+ starts always at the top-level +Object+ even if there is no leading "::". + + +X = :in_Object +module M + X = :in_M + + X # => :in_M + "::X".constantize # => :in_Object + "X".constantize # => :in_Object (!) +end + + +So, it is in general not equivalent to what Ruby would do in the same spot, had a real constant be evaluated. + +Mailer test cases obtain the mailer being tested from the name of the test class using +constantize+: + + +# action_mailer/test_case.rb +def determine_default_mailer(name) + name.sub(/Test$/, '').constantize +rescue NameError => e + raise NonInferrableMailerError.new(name) +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 3100ec4355320c088e0969bd5caf62c5c0042f4a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 3 Mar 2010 00:05:01 +0100 Subject: AS guide: documents String#humanize --- .../source/active_support_core_extensions.textile | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 149ebefbab..3370939861 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1527,6 +1527,35 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +humanize+ + +The method +humanize+ gives you a sensible name for display out of an attribute name. To do so it replaces underscores with spaces, removes any "_id" suffix, and capitalizes the first word: + + +"name".humanize # => "Name" +"author_id".humanize # => "Author" +"comments_count".humanize # => "Comments count" + + +The helper method +full_messages+ uses +humanize+ as a fallback to include attribute names: + + +def full_messages + full_messages = [] + + each do |attribute, messages| + ... + attr_name = attribute.to_s.gsub('.', '_').humanize + attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) + ... + end + + full_messages +end + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From a368f3b170a30ac9c5f479ba6a62bc4d1b82c972 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 3 Mar 2010 00:18:57 +0100 Subject: AS guide: documents String#foreign_key --- .../source/active_support_core_extensions.textile | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 3370939861..368dcc00b6 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1556,6 +1556,31 @@ end NOTE: Defined in +active_support/core_ext/string/inflections.rb+. +h5. +foreign_key+ + +The method +foreign_key+ gives a foreign key column name from a class name. To do so it demodulizes, underscores, and adds "_id": + + +"User".foreign_key # => "user_id" +"InvoiceLine".foreign_key # => "invoice_line_id" +"Admin::Session".foreign_key # => "session_id" + + +Pass a false argument if you do not want the underscore in "_id": + + +"User".foreign_key(false) # => "userid" + + +Associations use this method to infer foreign keys, for example +has_one+ and +has_many+ do this: + + +# active_record/associations.rb +foreign_key = options[:foreign_key] || reflection.active_record.name.foreign_key + + +NOTE: Defined in +active_support/core_ext/string/inflections.rb+. + h3. Extensions to +Numeric+ h4. Bytes -- cgit v1.2.3 From 71b29d1e56e630bafeca5345a358b4cdbd98c6e5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 3 Mar 2010 19:58:44 +0100 Subject: AS guide: How to Load Core Extensions --- .../source/active_support_core_extensions.textile | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 368dcc00b6..11f0bc956f 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -6,6 +6,62 @@ By referring to this guide you will learn the extensions to the Ruby core classe endprologue. +h3. How to Load Core Extensions + +In order to have a near zero default footprint, Active Support does not load anything by default. It is broken in small pieces so that you may load just what you need, and also has some convenience entry points to load related extensions in one shot, even everything. + +Thus, after a simple require like: + + +require 'active_support' + + +objects do not even respond to +blank?+, let's see how to load its definition. + +h4. Cherry-picking a Definition + +The most lightweight way to get +blank?+ is to cherry-pick the file that defines it. + +For every single method defined as a core extension this guide has a note that says where is such a method defined. In the case of +blank?+ the note reads: + +NOTE: Defined in +active_support/core_ext/object/blank.rb+. + +That means that this single call is enough: + + +require 'active_support/core_ext/object/blank' + + +Active Support has been carefully revised so that cherry-picking a file loads only strictly needed dependencies, if any. + +h4. Loading Grouped Core Extensions + +The next level is to simply load all extensions to +Object+. As a rule of thumb, extensions to +SomeClass+ are available in one shot by loading +active_support/core_ext/some_class+. + +Thus, if that would do, to have +blank?+ available we could just load all extensions to +Object+: + + +require 'active_support/core_ext/object' + + +h4. Loading All Core Extensions + +You may prefer just to load all core extensions, there is a file for that: + + +require 'active_support/core_ext' + + +h4. Loading All Active Support + +And finally, if you want to have all Active Support available just issue: + + +require 'active_support/all' + + +That does not even put the entire Active Support in memory upfront indeed, some stuff is configured via +autoload+, so it is only loaded if used. + h3. Extensions to All Objects h4. +blank?+ and +present?+ -- cgit v1.2.3 From dca6ddea043d79d9a1b0577bc1b8e2a93c96d555 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 4 Mar 2010 01:42:57 +0100 Subject: the guides generator needs fileutils --- railties/guides/rails_guides/generator.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/guides') diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 2f0718af75..7c8d26a1ea 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -1,4 +1,5 @@ require 'set' +require 'fileutils' module RailsGuides class Generator -- cgit v1.2.3 From 5245bf86353043050f569446333cf77faa8c5326 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Thu, 4 Mar 2010 01:48:56 +0100 Subject: Updated 3_0_release_notes so that it specifies that the rack-mount gem needs to be version 0.4 --- railties/guides/source/3_0_release_notes.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index 4bee0f537f..73479b3c0f 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -25,8 +25,9 @@ TIP: To install the Rails 3 prerelease beta using rubygems you have to install a # Use sudo if your setup requires it gem install tzinfo builder i18n memcache-client rack \ - rake rack-test rack-mount erubis mail text-format \ + rake rack-test erubis mail text-format \ thor bundler +gem install rack-mount -v=0.4 gem install rails --pre -- cgit v1.2.3 From 36d28f5168000b250fc87c88eef20294e059096d Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Thu, 4 Mar 2010 01:51:25 +0100 Subject: Update contribute guide so that it shows the new command to generate guides (rake generate_guides instead of rake guides) --- railties/guides/source/contribute.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/contribute.textile b/railties/guides/source/contribute.textile index 5087c2f385..a48edef79d 100644 --- a/railties/guides/source/contribute.textile +++ b/railties/guides/source/contribute.textile @@ -12,7 +12,7 @@ h3. How to Contribute? * All images are in the railties/guides/images directory. * Sample format : "Active Record Associations":http://github.com/lifo/docrails/blob/3e56a3832415476fdd1cb963980d0ae390ac1ed3/railties/guides/source/association_basics.textile * Sample output : "Active Record Associations":http://guides.rails.info/association_basics.html -* You can build the Guides during testing by running +rake guides+ in the +railties+ directory. +* You can build the Guides during testing by running +rake generate_guides+ in the +railties+ directory. h3. What to Contribute? -- cgit v1.2.3 From 18a9906b1ca3928d7a7d09304d5d457d024c6a02 Mon Sep 17 00:00:00 2001 From: Malcolm Locke Date: Sat, 6 Mar 2010 10:09:28 +1300 Subject: Corrects setting of :method on custom form_for --- railties/guides/source/form_helpers.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 0a76a0f06f..d33bb4b4ff 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -293,7 +293,7 @@ form_for(@article) ## Editing an existing article # long-style: -form_for(:article, @article, :url => article_path(@article), :method => "put") +form_for(:article, @article, :url => article_path(@article), :html => { :method => "put" }) # short-style: form_for(@article) -- cgit v1.2.3