railties 3.0.0.beta4 → 3.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +24 -6
  2. data/README.rdoc +25 -0
  3. data/guides/assets/javascripts/code_highlighter.js +0 -0
  4. data/guides/assets/javascripts/guides.js +0 -0
  5. data/guides/assets/stylesheets/print.css +0 -0
  6. data/guides/assets/stylesheets/reset.css +0 -0
  7. data/guides/assets/stylesheets/style.css +0 -0
  8. data/guides/source/3_0_release_notes.textile +5 -3
  9. data/guides/source/action_controller_overview.textile +19 -0
  10. data/guides/source/active_record_basics.textile +27 -21
  11. data/guides/source/active_record_querying.textile +39 -37
  12. data/guides/source/{activerecord_validations_callbacks.textile → active_record_validations_callbacks.textile} +30 -29
  13. data/guides/source/active_support_core_extensions.textile +232 -107
  14. data/guides/source/api_documentation_guidelines.textile +187 -0
  15. data/guides/source/association_basics.textile +45 -1
  16. data/guides/source/configuring.textile +7 -7
  17. data/guides/source/contributing_to_rails.textile +42 -15
  18. data/guides/source/form_helpers.textile +1 -1
  19. data/guides/source/generators.textile +37 -37
  20. data/guides/source/getting_started.textile +11 -11
  21. data/guides/source/i18n.textile +1 -1
  22. data/guides/source/index.html.erb +14 -6
  23. data/guides/source/initialization.textile +130 -124
  24. data/guides/source/layout.html.erb +5 -2
  25. data/guides/source/layouts_and_rendering.textile +2 -2
  26. data/guides/source/migrations.textile +4 -3
  27. data/guides/source/plugins.textile +15 -15
  28. data/guides/source/rails_application_templates.textile +2 -2
  29. data/guides/source/routing.textile +83 -62
  30. data/guides/source/security.textile +2 -2
  31. data/guides/w3c_validator.rb +30 -6
  32. data/lib/rails.rb +3 -3
  33. data/lib/rails/application.rb +43 -19
  34. data/lib/rails/application/bootstrap.rb +2 -0
  35. data/lib/rails/application/configuration.rb +3 -3
  36. data/lib/rails/application/finisher.rb +6 -6
  37. data/lib/rails/cli.rb +1 -19
  38. data/lib/rails/commands.rb +5 -5
  39. data/lib/rails/commands/application.rb +1 -1
  40. data/lib/rails/commands/console.rb +1 -4
  41. data/lib/rails/commands/generate.rb +0 -0
  42. data/lib/rails/commands/plugin.rb +57 -52
  43. data/lib/rails/commands/runner.rb +2 -1
  44. data/lib/rails/commands/server.rb +6 -2
  45. data/lib/rails/configuration.rb +2 -3
  46. data/lib/rails/console/app.rb +0 -2
  47. data/lib/rails/engine.rb +14 -15
  48. data/lib/rails/engine/configuration.rb +5 -5
  49. data/lib/rails/generators.rb +2 -3
  50. data/lib/rails/generators/actions.rb +4 -4
  51. data/lib/rails/generators/base.rb +1 -1
  52. data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +1 -6
  53. data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +4 -4
  54. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb +3 -3
  55. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +7 -7
  56. data/lib/rails/generators/erb/scaffold/templates/new.html.erb +2 -2
  57. data/lib/rails/generators/erb/scaffold/templates/show.html.erb +3 -3
  58. data/lib/rails/generators/generated_attribute.rb +2 -1
  59. data/lib/rails/generators/named_base.rb +24 -0
  60. data/lib/rails/generators/rails/app/app_generator.rb +10 -9
  61. data/lib/rails/generators/rails/app/templates/Gemfile +4 -3
  62. data/lib/rails/generators/rails/app/templates/README +6 -31
  63. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  64. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb +0 -1
  65. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  66. data/lib/rails/generators/rails/app/templates/config/application.rb +11 -11
  67. data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +36 -24
  68. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +1 -1
  69. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  70. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  71. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +3 -0
  72. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +3 -0
  73. data/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +1 -1
  74. data/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +2 -2
  75. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +2 -2
  76. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  77. data/lib/rails/generators/rails/app/templates/public/index.html +0 -17
  78. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +2027 -900
  79. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +114 -57
  80. data/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt +1 -1
  81. data/lib/rails/generators/rails/model/USAGE +1 -1
  82. data/lib/rails/generators/rails/resource/resource_generator.rb +4 -14
  83. data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +0 -2
  84. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +28 -30
  85. data/lib/rails/generators/resource_helpers.rb +1 -1
  86. data/lib/rails/generators/test_case.rb +25 -11
  87. data/lib/rails/generators/test_unit/model/model_generator.rb +1 -1
  88. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +0 -1
  89. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +13 -15
  90. data/lib/rails/info.rb +1 -2
  91. data/lib/rails/info_routes.rb +1 -1
  92. data/lib/rails/initializable.rb +3 -16
  93. data/lib/rails/paths.rb +31 -36
  94. data/lib/rails/plugin.rb +10 -6
  95. data/lib/rails/rack/logger.rb +11 -13
  96. data/lib/rails/railtie.rb +14 -42
  97. data/lib/rails/ruby_version_check.rb +19 -5
  98. data/lib/rails/script_rails_loader.rb +29 -0
  99. data/lib/rails/tasks/annotations.rake +2 -2
  100. data/lib/rails/tasks/documentation.rake +47 -16
  101. data/lib/rails/tasks/framework.rake +9 -9
  102. data/lib/rails/tasks/middleware.rake +1 -1
  103. data/lib/rails/tasks/misc.rake +5 -5
  104. data/lib/rails/tasks/routes.rake +1 -1
  105. data/lib/rails/tasks/tmp.rake +5 -5
  106. data/lib/rails/test_unit/testing.rake +38 -14
  107. data/lib/rails/version.rb +1 -1
  108. metadata +29 -17
  109. data/README +0 -281
  110. data/lib/rails/application/routes_reloader.rb +0 -46
  111. data/lib/rails/log_subscriber.rb +0 -115
  112. data/lib/rails/log_subscriber/test_helper.rb +0 -97
  113. data/lib/rails/webrick_server.rb +0 -156
@@ -50,7 +50,7 @@
50
50
  <dd><a href="getting_started.html">Getting Started with Rails</a></dd>
51
51
  <dt>Models</dt>
52
52
  <dd><a href="migrations.html">Rails Database Migrations</a></dd>
53
- <dd><a href="activerecord_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
53
+ <dd><a href="active_record_validations_callbacks.html">Active Record Validations and Callbacks</a></dd>
54
54
  <dd><a href="association_basics.html">Active Record Associations</a></dd>
55
55
  <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd>
56
56
  <dt>Views</dt>
@@ -71,13 +71,16 @@
71
71
  <dd><a href="configuring.html">Configuring Rails Applications</a></dd>
72
72
  <dd><a href="command_line.html">Rails Command Line Tools and Rake Tasks</a></dd>
73
73
  <dd><a href="caching_with_rails.html">Caching with Rails</a></dd>
74
- <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
75
74
 
76
75
  <dt>Extending Rails</dt>
77
76
  <dd><a href="plugins.html">The Basics of Creating Rails Plugins</a></dd>
78
77
  <dd><a href="rails_on_rack.html">Rails on Rack</a></dd>
79
78
  <dd><a href="generators.html">Adding a Generator to Your Plugin</a></dd>
80
79
 
80
+ <dt>Contributing to Rails</dt>
81
+ <dd><a href="contributing_to_rails.html">Contributing to Rails</a></dd>
82
+ <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd>
83
+
81
84
  <dt>Release Notes</dt>
82
85
  <dd><a href="3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></dd>
83
86
  <dd><a href="2_3_release_notes.html">Ruby on Rails 2.3 Release Notes</a></dd>
@@ -2,7 +2,7 @@ h2. Layouts and Rendering in Rails
2
2
 
3
3
  This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to:
4
4
 
5
- * Use the various rendering methods built in to Rails
5
+ * Use the various rendering methods built into Rails
6
6
  * Create layouts with multiple content sections
7
7
  * Use partials to DRY up your views
8
8
  * Use nested layouts (sub-templates)
@@ -1168,7 +1168,7 @@ Suppose you have the following +ApplicationController+ layout:
1168
1168
  <body>
1169
1169
  <div id="top_menu">Top menu items here</div>
1170
1170
  <div id="menu">Menu items here</div>
1171
- <div id="content"><%= yield(:content) or yield %></div>
1171
+ <div id="content"><%= content_for?(:content) ? yield(:content) : yield %></div>
1172
1172
  </body>
1173
1173
  </html>
1174
1174
  </erb>
@@ -1,6 +1,6 @@
1
1
  h2. Migrations
2
2
 
3
- Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run it. You'd also have to keep track of which changes need to be run against the production machines next time you deploy.
3
+ Migrations are a convenient way for you to alter your database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them. You'd also have to keep track of which changes need to be run against the production machines next time you deploy.
4
4
 
5
5
  Active Record tracks which migrations have already been run so all you have to do is update your source and run +rake db:migrate+. Active Record will work out which migrations should be run. It will also update your +db/schema.rb+ file to match the structure of your database.
6
6
 
@@ -234,7 +234,7 @@ end
234
234
 
235
235
  which creates a +products+ table with a column called +name+ (and as discussed below, an implicit +id+ column).
236
236
 
237
- The object yielded to the block allows you create columns on the table. There are two ways of doing this: The first (traditional) form looks like
237
+ The object yielded to the block allows you to create columns on the table. There are two ways of doing this: The first (traditional) form looks like
238
238
 
239
239
  <ruby>
240
240
  create_table :products do |t|
@@ -250,7 +250,7 @@ create_table :products do |t|
250
250
  end
251
251
  </ruby>
252
252
 
253
- By default +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass +:id => false+. If you need to pass database specific options you can place an SQL fragment in the +:options+ option. For example
253
+ By default +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass +:id => false+. If you need to pass database specific options you can place a SQL fragment in the +:options+ option. For example
254
254
 
255
255
  <ruby>
256
256
  create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
@@ -592,4 +592,5 @@ h3. Changelog
592
592
 
593
593
  "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/6
594
594
 
595
+ * July 15, 2010: minor typos corrected by "Jaime Iniesta":http://jaimeiniesta.com
595
596
  * September 14, 2008: initial version by "Frederick Cheung":credits.html#fcheung
@@ -205,7 +205,7 @@ def load_schema
205
205
 
206
206
  ActiveRecord::Base.establish_connection(config[db_adapter])
207
207
  load(File.dirname(__FILE__) + "/schema.rb")
208
- require File.dirname(__FILE__) + '/../rails/init.rb'
208
+ require File.dirname(__FILE__) + '/../rails/init'
209
209
  end
210
210
  </ruby>
211
211
 
@@ -218,7 +218,7 @@ Once you have these files in place, you can write your first test to ensure that
218
218
  <ruby>
219
219
  # vendor/plugins/yaffle/test/yaffle_test.rb
220
220
 
221
- require File.dirname(__FILE__) + '/test_helper.rb'
221
+ require File.dirname(__FILE__) + '/test_helper'
222
222
 
223
223
  class YaffleTest < Test::Unit::TestCase
224
224
  load_schema
@@ -284,7 +284,7 @@ In this example you will add a method to String named +to_squawk+. To begin, cr
284
284
  <ruby>
285
285
  # vendor/plugins/yaffle/test/core_ext_test.rb
286
286
 
287
- require File.dirname(__FILE__) + '/test_helper.rb'
287
+ require File.dirname(__FILE__) + '/test_helper'
288
288
 
289
289
  class CoreExtTest < Test::Unit::TestCase
290
290
  def test_to_squawk_prepends_the_word_squawk
@@ -311,7 +311,7 @@ NoMethodError: undefined method `to_squawk' for "Hello World":String
311
311
 
312
312
  Great - now you are ready to start development.
313
313
 
314
- Then in +lib/yaffle.rb+ require +lib/core_ext.rb+:
314
+ Then in +lib/yaffle.rb+ require +lib/core_ext+:
315
315
 
316
316
  <ruby>
317
317
  # vendor/plugins/yaffle/lib/yaffle.rb
@@ -380,7 +380,7 @@ To begin, set up your files so that you have:
380
380
  * *vendor/plugins/yaffle/test/acts_as_yaffle_test.rb*
381
381
 
382
382
  <ruby>
383
- require File.dirname(__FILE__) + '/test_helper.rb'
383
+ require File.dirname(__FILE__) + '/test_helper'
384
384
 
385
385
  class ActsAsYaffleTest < Test::Unit::TestCase
386
386
  end
@@ -436,7 +436,7 @@ To start out, write a failing test that shows the behavior you'd like:
436
436
  * *vendor/plugins/yaffle/test/acts_as_yaffle_test.rb*
437
437
 
438
438
  <ruby>
439
- require File.dirname(__FILE__) + '/test_helper.rb'
439
+ require File.dirname(__FILE__) + '/test_helper'
440
440
 
441
441
  class Hickwall < ActiveRecord::Base
442
442
  acts_as_yaffle
@@ -489,7 +489,7 @@ To start out, write a failing test that shows the behavior you'd like:
489
489
  * *vendor/plugins/yaffle/test/acts_as_yaffle_test.rb*
490
490
 
491
491
  <ruby>
492
- require File.dirname(__FILE__) + '/test_helper.rb'
492
+ require File.dirname(__FILE__) + '/test_helper'
493
493
 
494
494
  class Hickwall < ActiveRecord::Base
495
495
  acts_as_yaffle
@@ -579,7 +579,7 @@ As always, start with a test:
579
579
  * *vendor/plugins/yaffle/test/woodpecker_test.rb:*
580
580
 
581
581
  <ruby>
582
- require File.dirname(__FILE__) + '/test_helper.rb'
582
+ require File.dirname(__FILE__) + '/test_helper'
583
583
 
584
584
  class WoodpeckerTest < Test::Unit::TestCase
585
585
  load_schema
@@ -633,7 +633,7 @@ You can test your plugin's controller as you would test any other controller:
633
633
  * *vendor/plugins/yaffle/test/woodpeckers_controller_test.rb:*
634
634
 
635
635
  <ruby>
636
- require File.dirname(__FILE__) + '/test_helper.rb'
636
+ require File.dirname(__FILE__) + '/test_helper'
637
637
  require 'woodpeckers_controller'
638
638
  require 'action_controller/test_process'
639
639
 
@@ -693,7 +693,7 @@ You can test your plugin's helper as you would test any other helper:
693
693
  * *vendor/plugins/yaffle/test/woodpeckers_helper_test.rb*
694
694
 
695
695
  <ruby>
696
- require File.dirname(__FILE__) + '/test_helper.rb'
696
+ require File.dirname(__FILE__) + '/test_helper'
697
697
  include WoodpeckersHelper
698
698
 
699
699
  class WoodpeckersHelperTest < Test::Unit::TestCase
@@ -816,7 +816,7 @@ This section will describe how to create a simple generator that adds a file. F
816
816
  * *vendor/plugins/yaffle/test/definition_generator_test.rb*
817
817
 
818
818
  <ruby>
819
- require File.dirname(__FILE__) + '/test_helper.rb'
819
+ require File.dirname(__FILE__) + '/test_helper'
820
820
  require 'rails_generator'
821
821
  require 'rails_generator/scripts/generate'
822
822
 
@@ -990,7 +990,7 @@ To start, add the following test method:
990
990
  * *vendor/plugins/yaffle/test/route_generator_test.rb*
991
991
 
992
992
  <ruby>
993
- require File.dirname(__FILE__) + '/test_helper.rb'
993
+ require File.dirname(__FILE__) + '/test_helper'
994
994
  require 'rails_generator'
995
995
  require 'rails_generator/scripts/generate'
996
996
  require 'rails_generator/scripts/destroy'
@@ -1205,7 +1205,7 @@ This example will demonstrate how to use one of the built-in generator methods n
1205
1205
  * *vendor/plugins/yaffle/test/yaffle_migration_generator_test.rb*
1206
1206
 
1207
1207
  <ruby>
1208
- require File.dirname(__FILE__) + '/test_helper.rb'
1208
+ require File.dirname(__FILE__) + '/test_helper'
1209
1209
  require 'rails_generator'
1210
1210
  require 'rails_generator/scripts/generate'
1211
1211
 
@@ -1274,7 +1274,7 @@ class YaffleMigrationGenerator < Rails::Generator::NamedBase
1274
1274
  end
1275
1275
 
1276
1276
  def yaffle_local_assigns
1277
- returning(assigns = {}) do
1277
+ {}.tap do |assigns|
1278
1278
  assigns[:migration_action] = "add"
1279
1279
  assigns[:class_name] = "add_yaffle_fields_to_#{custom_file_name}"
1280
1280
  assigns[:table_name] = custom_file_name
@@ -1284,7 +1284,7 @@ class YaffleMigrationGenerator < Rails::Generator::NamedBase
1284
1284
  end
1285
1285
  </ruby>
1286
1286
 
1287
- The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built in rails +migration_template+ method, and reuses the built-in rails migration template.
1287
+ The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built-in rails +migration_template+ method, and reuses the built-in rails migration template.
1288
1288
 
1289
1289
  It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off.
1290
1290
 
@@ -51,11 +51,11 @@ h4. gem(name, options = {})
51
51
 
52
52
  Adds a +config.gem+ entry for the supplied gem to the generated application’s +config/environment.rb+.
53
53
 
54
- For example, if your application depends on the gems +bj+ and +hpricot+ :
54
+ For example, if your application depends on the gems +bj+ and +nokogiri+ :
55
55
 
56
56
  <ruby>
57
57
  gem "bj"
58
- gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
58
+ gem "nokogiri"
59
59
  </ruby>
60
60
 
61
61
  Please note that this will NOT install the gems for you. So you may want to run the +rake gems:install+ task too :
@@ -3,16 +3,16 @@ h2. Rails Routing from the Outside In
3
3
  This guide covers the user-facing features of Rails routing. By referring to this guide, you will be able to:
4
4
 
5
5
  * Understand the code in +routes.rb+
6
- * Construct your own routes, using either the preferred resourceful style or with the @match@ method
6
+ * Construct your own routes, using either the preferred resourceful style or with the <tt>match</tt> method
7
7
  * Identify what parameters to expect an action to receive
8
- * Automatically create URLs using route helpers
8
+ * Automatically create paths and URLs using route helpers
9
9
  * Use advanced techniques such as constraints and Rack endpoints
10
10
 
11
11
  endprologue.
12
12
 
13
13
  h3. The Purpose of the Rails Router
14
14
 
15
- The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate URLs, avoiding the need to hardcode URL strings in your views.
15
+ The Rails router recognizes URLs and dispatches them to a controller's action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.
16
16
 
17
17
  h4. Connecting URLs to Code
18
18
 
@@ -30,9 +30,9 @@ match "/patients/:id" => "patients#show"
30
30
 
31
31
  the request is dispatched to the +patients+ controller's +show+ action with <tt>{ :id => "17" }</tt> in +params+.
32
32
 
33
- h4. Generating URLs from Code
33
+ h4. Generating Paths and URLs from Code
34
34
 
35
- You can also generate routes. If your application contains this code:
35
+ You can also generate paths and URLs. If your application contains this code:
36
36
 
37
37
  <ruby>
38
38
  @patient = Patient.find(17)
@@ -76,7 +76,7 @@ resources :photos
76
76
 
77
77
  creates seven different routes in your application, all mapping to the +Photos+ controller:
78
78
 
79
- |_. Verb |_.URL |_.action |_.used for|
79
+ |_. Verb |_.Path |_.action |_.used for|
80
80
  |GET |/photos |index |display a list of all photos|
81
81
  |GET |/photos/new |new |return an HTML form for creating a new photo|
82
82
  |POST |/photos |create |create a new photo|
@@ -85,7 +85,7 @@ creates seven different routes in your application, all mapping to the +Photos+
85
85
  |PUT |/photos/:id |update |update a specific photo|
86
86
  |DELETE |/photos/:id |destroy |delete a specific photo|
87
87
 
88
- h4. URLs and Paths
88
+ h4. Paths and URLs
89
89
 
90
90
  Creating a resourceful route will also expose a number of helpers to the controllers in your application. In the case of +resources :photos+:
91
91
 
@@ -130,7 +130,7 @@ resource :geocoder
130
130
 
131
131
  creates six different routes in your application, all mapping to the +Geocoders+ controller:
132
132
 
133
- |_. Verb |_.URL |_.action |_.used for|
133
+ |_. Verb |_.Path |_.action |_.used for|
134
134
  |GET |/geocoder/new |new |return an HTML form for creating the geocoder|
135
135
  |POST |/geocoder |create |create the new geocoder|
136
136
  |GET |/geocoder |show |display the one and only geocoder resource|
@@ -160,7 +160,7 @@ end
160
160
 
161
161
  This will create a number of routes for each of the +posts+ and +comments+ controller. For +Admin::PostsController+, Rails will create:
162
162
 
163
- |_. Verb |_.URL |_.action |_. helper |
163
+ |_. Verb |_.Path |_.action |_. helper |
164
164
  |GET |/admin/photos |index | admin_photos_path |
165
165
  |GET |/admin/photos/new |new | new_admin_photos_path |
166
166
  |POST |/admin/photos |create | admin_photos_path |
@@ -197,16 +197,16 @@ or, for a single case
197
197
  resources :posts, :path => "/admin"
198
198
  </ruby>
199
199
 
200
- In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following URLs map to +PostsController+:
200
+ In each of these cases, the named routes remain the same as if you did not use +scope+. In the last case, the following paths map to +PostsController+:
201
201
 
202
- |_. Verb |_.URL |_.action |_. helper |
203
- |GET |photos |index | photos_path |
204
- |GET |photos/new |new | photos_path |
205
- |POST |photos |create | photos_path |
206
- |GET |photos/1 |show | photo_path(id) |
207
- |GET |photos/1/edit |edit | dmin_photo_path(id) |
208
- |PUT |photos/1 |update | photo_path(id) |
209
- |DELETE |photos/1 |destroy | photo_path(id) |
202
+ |_. Verb |_.Path |_.action |_. helper |
203
+ |GET |/admin/photos |index | photos_path |
204
+ |GET |/admin/photos/new |new | photos_path |
205
+ |POST |/admin/photos |create | photos_path |
206
+ |GET |/admin/photos/1 |show | photo_path(id) |
207
+ |GET |/admin/photos/1/edit |edit | edit_photo_path(id) |
208
+ |PUT |/admin/photos/1 |update | photo_path(id) |
209
+ |DELETE |/admin/photos/1 |destroy | photo_path(id) |
210
210
 
211
211
  h4. Nested Resources
212
212
 
@@ -232,7 +232,7 @@ end
232
232
 
233
233
  In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine:
234
234
 
235
- |_.Verb |_.URL |_.action |_.used for|
235
+ |_.Verb |_.Path |_.action |_.used for|
236
236
  |GET |/magazines/1/ads |index |display a list of all ads for a specific magazine|
237
237
  |GET |/magazines/1/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine|
238
238
  |POST |/magazines/1/ads |create |create a new ad belonging to a specific magazine|
@@ -256,7 +256,7 @@ resources :publishers do
256
256
  end
257
257
  </ruby>
258
258
 
259
- Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize URLs such as
259
+ Deeply-nested resources quickly become cumbersome. In this case, for example, the application would recognize paths such as
260
260
 
261
261
  <pre>
262
262
  /publishers/1/magazines/2/photos/3
@@ -266,9 +266,9 @@ The corresponding route helper would be +publisher_magazine_photo_url+, requirin
266
266
 
267
267
  TIP: _Resources should never be nested more than 1 level deep._
268
268
 
269
- h4. Creating URLs From Objects
269
+ h4. Creating Paths and URLs From Objects
270
270
 
271
- In addition to using the routing helpers, Rails can also create URLs from an array of parameters. For example, suppose you have this set of routes:
271
+ In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes:
272
272
 
273
273
  <ruby>
274
274
  resources :magazines do
@@ -308,7 +308,7 @@ You are not limited to the seven routes that RESTful routing creates by default.
308
308
 
309
309
  h5. Adding Member Routes
310
310
 
311
- To add a member route, just add +member+ block into resource block:
311
+ To add a member route, just add a +member+ block into the resource block:
312
312
 
313
313
  <ruby>
314
314
  resources :photos do
@@ -318,9 +318,9 @@ resources :photos do
318
318
  end
319
319
  </ruby>
320
320
 
321
- This will recognize +/photos/1/preview+ with GET, and route to the +preview+ action of +PhotosController+. It will also create the +preview_photo_url+ and +preview_photo_path+ helpers.
321
+ This will recognize +/photos/1/preview+ with GET, and route to the +preview+ action of +PhotosController+. It will also create the +preview_photo_url+ and +preview_photo_path+ helpers.
322
322
 
323
- Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, or +delete+ here. If you don't have multiple +member+ routes, you can also passing +:on+ to a route.
323
+ Within the block of member routes, each route name specifies the HTTP verb that it will recognize. You can use +get+, +put+, +post+, or +delete+ here. If you don't have multiple +member+ routes, you can also pass +:on+ to a route, eliminating the block:
324
324
 
325
325
  <ruby>
326
326
  resources :photos do
@@ -340,9 +340,9 @@ resources :photos do
340
340
  end
341
341
  </ruby>
342
342
 
343
- This will enable Rails to recognize URLs such as +/photos/search+ with GET, and route to the +search+ action of +PhotosController+. It will also create the +search_photos_url+ and +search_photos_path+ route helpers.
343
+ This will enable Rails to recognize paths such as +/photos/search+ with GET, and route to the +search+ action of +PhotosController+. It will also create the +search_photos_url+ and +search_photos_path+ route helpers.
344
344
 
345
- Just as with member routes, you can pass +:on+ to a route.
345
+ Just as with member routes, you can pass +:on+ to a route:
346
346
 
347
347
  <ruby>
348
348
  resources :photos do
@@ -380,17 +380,23 @@ You can set up as many dynamic segments within a regular route as you like. Anyt
380
380
  match ':controller/:action/:id/:user_id'
381
381
  </ruby>
382
382
 
383
- An incoming URL of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+.
383
+ An incoming path of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+.
384
+
385
+ NOTE: You can't use +namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g:
386
+
387
+ <ruby>
388
+ match ':controller(/:action(/:id))', :controller => /admin\/[^\/]+/
389
+ </ruby>
384
390
 
385
391
  h4. Static Segments
386
392
 
387
- You can specify static segments when creating a route.
393
+ You can specify static segments when creating a route:
388
394
 
389
395
  <ruby>
390
396
  match ':controller/:action/:id/with_user/:user_id'
391
397
  </ruby>
392
398
 
393
- This route would respond to URLs such as +/photos/show/1/with_user/2+. In this case, +params+ would be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
399
+ This route would respond to paths such as +/photos/show/1/with_user/2+. In this case, +params+ would be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
394
400
 
395
401
  h4. The Query String
396
402
 
@@ -400,7 +406,7 @@ The +params+ will also include any parameters from the query string. For example
400
406
  match ':controller/:action/:id'
401
407
  </ruby>
402
408
 
403
- An incoming URL of +/photos/show/1?user_id=2+ will be dispatched to the +show+ action of the +Photos+ controller. +params+ will be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
409
+ An incoming path of +/photos/show/1?user_id=2+ will be dispatched to the +show+ action of the +Photos+ controller. +params+ will be <tt>{ :controller => "photos", :action => "show", :id => "1", :user_id => "2" }</tt>.
404
410
 
405
411
  h4. Defining Defaults
406
412
 
@@ -410,7 +416,7 @@ You do not need to explicitly use the +:controller+ and +:action+ symbols within
410
416
  match 'photos/:id' => 'photos#show'
411
417
  </ruby>
412
418
 
413
- With this route, Rails will match an incoming URL of +/photos/12+ to the +show+ action of +PhotosController+.
419
+ With this route, Rails will match an incoming path of +/photos/12+ to the +show+ action of +PhotosController+.
414
420
 
415
421
  You can also define other defaults in a route by supplying a hash for the +:defaults+ option. This even applies to parameters that you do not specify as dynamic segments. For example:
416
422
 
@@ -435,13 +441,28 @@ h4. Segment Constraints
435
441
  You can use the +:constraints+ option to enforce a format for a dynamic segment:
436
442
 
437
443
  <ruby>
438
- match 'photo/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }
444
+ match 'photos/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }
445
+ </ruby>
446
+
447
+ This route would match paths such as +/photos/A12345+. You can more succinctly express the same route this way:
448
+
449
+ <ruby>
450
+ match 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/
439
451
  </ruby>
440
452
 
441
- This route would match URLs such as +/photo/A12345+. You can more succinctly express the same route this way:
453
+ +:constraints+ takes regular expression. However note that regexp anchors can't be used within constraints. For example following route will not work:
442
454
 
443
455
  <ruby>
444
- match 'photo/:id' => 'photos#show', :id => /[A-Z]\d{5}/
456
+ match '/:id' => 'posts#show', :constraints => {:id => /^\d/}
457
+ </ruby>
458
+
459
+ However, note that you don't need to use anchors because all routes are anchored at the start.
460
+
461
+ For example, the following routes would allow for +posts+ with +to_param+ values like +1-hello-world+ that always begin with a number and +users+ with +to_param+ values like +david+ that never begin with a number to share the root namespace:
462
+
463
+ <ruby>
464
+ match '/:id' => 'posts#show', :constraints => { :id => /\d.+/ }
465
+ match '/:username' => 'users#show'
445
466
  </ruby>
446
467
 
447
468
  h4. Request-Based Constraints
@@ -451,7 +472,7 @@ You can also constrain a route based on any method on the <a href="action_contro
451
472
  You specify a request-based constraint the same way that you specify a segment constraint:
452
473
 
453
474
  <ruby>
454
- match "photo", :constraints => {:subdomain => "admin"}
475
+ match "photos", :constraints => {:subdomain => "admin"}
455
476
  </ruby>
456
477
 
457
478
  You can also specify constrains in a block form:
@@ -490,10 +511,10 @@ h4. Route Globbing
490
511
  Route globbing is a way to specify that a particular parameter should be matched to all the remaining parts of a route. For example
491
512
 
492
513
  <ruby>
493
- match 'photo/*other' => 'photos#unknown'
514
+ match 'photos/*other' => 'photos#unknown'
494
515
  </ruby>
495
516
 
496
- This route would match +photo/12+ or +/photo/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+.
517
+ This route would match +photos/12+ or +/photos/long/path/to/12+, setting +params[:other]+ to +"12"+ or +"long/path/to/12"+.
497
518
 
498
519
  h4. Redirection
499
520
 
@@ -552,9 +573,9 @@ The +:controller+ option lets you explicitly specify a controller to use for the
552
573
  resources :photos, :controller => "images"
553
574
  </ruby>
554
575
 
555
- will recognize incoming URLs beginning with +/photo+ but route to the +Images+ controller:
576
+ will recognize incoming paths beginning with +/photo+ but route to the +Images+ controller:
556
577
 
557
- |_. Verb |_.URL |_.action |
578
+ |_. Verb |_.Path |_.action |
558
579
  |GET |/photos |index |
559
580
  |GET |/photos/new |new |
560
581
  |POST |/photos |create |
@@ -563,7 +584,7 @@ will recognize incoming URLs beginning with +/photo+ but route to the +Images+ c
563
584
  |PUT |/photos/1 |update |
564
585
  |DELETE |/photos/1 |destroy |
565
586
 
566
- NOTE: Use +photos_path+, +new_photos_path+, etc. to generate URLs for this resource.
587
+ NOTE: Use +photos_path+, +new_photos_path+, etc. to generate paths for this resource.
567
588
 
568
589
  h4. Specifying Constraints
569
590
 
@@ -575,7 +596,7 @@ resources :photos, :constraints => {:id => /[A-Z][A-Z][0-9]+/}
575
596
 
576
597
  This declaration constrains the +:id+ parameter to match the supplied regular expression. So, in this case, the router would no longer match +/photos/1+ to this route. Instead, +/photos/RR27+ would match.
577
598
 
578
- You can specify a single constraint to a apply to a number of routes by using the block form:
599
+ You can specify a single constraint to apply to a number of routes by using the block form:
579
600
 
580
601
  <ruby>
581
602
  constraints(:id => /[A-Z][A-Z][0-9]+/) do
@@ -594,10 +615,10 @@ The +:as+ option lets you override the normal naming for the named route helpers
594
615
  resources :photos, :as => "images"
595
616
  </ruby>
596
617
 
597
- will recognize incoming URLs beginning with +/photos+ and route the requests to +PhotosController+:
618
+ will recognize incoming paths beginning with +/photos+ and route the requests to +PhotosController+:
598
619
 
599
- |_.HTTP verb|_.URL |_.action |_.named helper |
600
- |GET |/photos |index | images_path_ |
620
+ |_.HTTP verb|_.Path |_.action |_.named helper |
621
+ |GET |/photos |index | images_path |
601
622
  |GET |/photos/new |new | new_image_path |
602
623
  |POST |/photos |create | images_path |
603
624
  |GET |/photos/1 |show | image_path |
@@ -607,20 +628,20 @@ will recognize incoming URLs beginning with +/photos+ and route the requests to
607
628
 
608
629
  h4. Overriding the +new+ and +edit+ Segments
609
630
 
610
- The +:path_names+ option lets you override the automatically-generated "new" and "edit" segments in URLs:
631
+ The +:path_names+ option lets you override the automatically-generated "new" and "edit" segments in paths:
611
632
 
612
633
  <ruby>
613
634
  resources :photos, :path_names => { :new => 'make', :edit => 'change' }
614
635
  </ruby>
615
636
 
616
- This would cause the routing to recognize URLs such as
637
+ This would cause the routing to recognize paths such as
617
638
 
618
639
  <plain>
619
640
  /photos/make
620
641
  /photos/1/change
621
642
  </plain>
622
643
 
623
- NOTE: The actual action names aren't changed by this option. The two URLs shown would still route to the new and edit actions.
644
+ NOTE: The actual action names aren't changed by this option. The two paths shown would still route to the +new+ and +edit+ actions.
624
645
 
625
646
  TIP: If you find yourself wanting to change this option uniformly for all of your routes, you can use a scope:
626
647
 
@@ -630,13 +651,13 @@ scope :path_names => { :new => "make" } do
630
651
  end
631
652
  </ruby>
632
653
 
633
- h4. Overriding the Named Helper Prefix
654
+ h4. Prefixing the Named Route Helpers
634
655
 
635
- You can use the :name_prefix option to add a prefix to the named route helpers that Rails generates for a route. You can use this option to prevent collisions between routes using a path scope.
656
+ You can use the +:as+ option to prefix the named route helpers that Rails generates for a route. Use this option to prevent name collisions between routes using a path scope.
636
657
 
637
658
  <ruby>
638
659
  scope "admin" do
639
- resources :photos, :name_prefix => "admin"
660
+ resources :photos, :as => "admin_photos"
640
661
  end
641
662
 
642
663
  resources :photos
@@ -644,17 +665,17 @@ resources :photos
644
665
 
645
666
  This will provide route helpers such as +admin_photos_path+, +new_admin_photo_path+ etc.
646
667
 
647
- You could specify a name prefix to use for a group of routes in the scope:
668
+ To prefix a group of routes, use +:as+ with +scope+:
648
669
 
649
670
  <ruby>
650
- scope "admin", :name_prefix => "admin" do
671
+ scope "admin", :as => "admin" do
651
672
  resources :photos, :accounts
652
673
  end
653
674
 
654
675
  resources :photos, :accounts
655
676
  </ruby>
656
677
 
657
- NOTE: The +namespace+ scope will automatically add a +:name_prefix+ as well as +:module+ and +:path+ prefixes.
678
+ NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes.
658
679
 
659
680
  h4. Restricting the Routes Created
660
681
 
@@ -688,7 +709,7 @@ end
688
709
 
689
710
  Rails now creates routes to the +CategoriesControlleR+.
690
711
 
691
- |_.HTTP verb|_.URL |_.action |
712
+ |_.HTTP verb|_.Path |_.action |
692
713
  |GET |/kategorien |index |
693
714
  |GET |/kategorien/neu |new |
694
715
  |POST |/kategorien |create |
@@ -699,21 +720,21 @@ Rails now creates routes to the +CategoriesControlleR+.
699
720
 
700
721
  h4. Overriding the Singular Form
701
722
 
702
- If you want to customize the singular name of the route in the named helpers, you can use the +:singular+ option.
723
+ If you want to define the singular form of a resource, you should add additional rules to the +Inflector+.
703
724
 
704
725
  <ruby>
705
- resources :teeth, :singular => "tooth"
726
+ ActiveSupport::Inflector.inflections do |inflect|
727
+ inflect.irregular 'tooth', 'teeth'
728
+ end
706
729
  </ruby>
707
730
 
708
- TIP: If you want to define the singular form of a word for your entire application, you should add additional rules to the +Inflector+ instead.
709
-
710
- h4(#nested-name-prefix). Using +:name_prefix+ in Nested Resources
731
+ h4(#nested-names). Using +:as+ in Nested Resources
711
732
 
712
- The +:name_prefix+ option overrides the automatically-generated prefix for the parent resource in nested route helpers. For example,
733
+ The +:as+ option overrides the automatically-generated name for the resource in nested route helpers. For example,
713
734
 
714
735
  <ruby>
715
736
  resources :magazines do
716
- resources :ads, :name_prefix => 'periodical'
737
+ resources :ads, :as => 'periodical_ads'
717
738
  end
718
739
  </ruby>
719
740