railties 3.0.20 → 3.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/CHANGELOG +36 -49
  2. data/README.rdoc +2 -1
  3. data/guides/assets/stylesheets/fixes.css +16 -0
  4. data/guides/rails_guides.rb +2 -2
  5. data/guides/rails_guides/generator.rb +8 -3
  6. data/guides/rails_guides/textile_extensions.rb +4 -2
  7. data/guides/source/2_2_release_notes.textile +3 -3
  8. data/guides/source/2_3_release_notes.textile +2 -2
  9. data/guides/source/3_0_release_notes.textile +14 -14
  10. data/guides/source/action_controller_overview.textile +54 -79
  11. data/guides/source/action_mailer_basics.textile +39 -9
  12. data/guides/source/action_view_overview.textile +257 -211
  13. data/guides/source/active_record_basics.textile +1 -1
  14. data/guides/source/active_record_querying.textile +217 -27
  15. data/guides/source/active_record_validations_callbacks.textile +94 -25
  16. data/guides/source/active_support_core_extensions.textile +109 -77
  17. data/guides/source/ajax_on_rails.textile +15 -150
  18. data/guides/source/api_documentation_guidelines.textile +12 -12
  19. data/guides/source/association_basics.textile +74 -60
  20. data/guides/source/caching_with_rails.textile +59 -60
  21. data/guides/source/command_line.textile +46 -47
  22. data/guides/source/configuring.textile +55 -37
  23. data/guides/source/contribute.textile +7 -7
  24. data/guides/source/contributing_to_ruby_on_rails.textile +14 -23
  25. data/guides/source/credits.html.erb +3 -3
  26. data/guides/source/debugging_rails_applications.textile +59 -46
  27. data/guides/source/form_helpers.textile +76 -31
  28. data/guides/source/generators.textile +39 -40
  29. data/guides/source/getting_started.textile +73 -94
  30. data/guides/source/i18n.textile +64 -58
  31. data/guides/source/index.html.erb +3 -3
  32. data/guides/source/initialization.textile +634 -3284
  33. data/guides/source/layout.html.erb +6 -7
  34. data/guides/source/layouts_and_rendering.textile +59 -60
  35. data/guides/source/migrations.textile +63 -59
  36. data/guides/source/nested_model_forms.textile +2 -2
  37. data/guides/source/performance_testing.textile +16 -16
  38. data/guides/source/plugins.textile +236 -1280
  39. data/guides/source/rails_application_templates.textile +37 -29
  40. data/guides/source/rails_on_rack.textile +4 -9
  41. data/guides/source/routing.textile +96 -75
  42. data/guides/source/ruby_on_rails_guides_guidelines.textile +19 -12
  43. data/guides/source/security.textile +57 -30
  44. data/guides/source/testing.textile +26 -24
  45. data/guides/w3c_validator.rb +2 -2
  46. data/lib/rails.rb +1 -7
  47. data/lib/rails/application.rb +46 -76
  48. data/lib/rails/application/bootstrap.rb +6 -11
  49. data/lib/rails/application/configuration.rb +43 -40
  50. data/lib/rails/application/finisher.rb +16 -4
  51. data/lib/rails/application/railties.rb +6 -24
  52. data/lib/rails/application/routes_reloader.rb +45 -0
  53. data/lib/rails/backtrace_cleaner.rb +1 -1
  54. data/lib/rails/cli.rb +7 -5
  55. data/lib/rails/commands.rb +27 -2
  56. data/lib/rails/commands/application.rb +14 -1
  57. data/lib/rails/commands/benchmarker.rb +3 -1
  58. data/lib/rails/commands/dbconsole.rb +2 -2
  59. data/lib/rails/commands/destroy.rb +3 -1
  60. data/lib/rails/commands/generate.rb +3 -1
  61. data/lib/rails/commands/plugin.rb +2 -7
  62. data/lib/rails/commands/plugin_new.rb +10 -0
  63. data/lib/rails/commands/profiler.rb +3 -1
  64. data/lib/rails/commands/server.rb +4 -0
  65. data/lib/rails/configuration.rb +8 -81
  66. data/lib/rails/console/app.rb +2 -2
  67. data/lib/rails/engine.rb +460 -78
  68. data/lib/rails/engine/configuration.rb +46 -49
  69. data/lib/rails/engine/railties.rb +33 -0
  70. data/lib/rails/generators.rb +11 -5
  71. data/lib/rails/generators/actions.rb +2 -27
  72. data/lib/rails/generators/app_base.rb +216 -0
  73. data/lib/rails/generators/base.rb +3 -2
  74. data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -1
  75. data/lib/rails/generators/generated_attribute.rb +2 -1
  76. data/lib/rails/generators/migration.rb +6 -2
  77. data/lib/rails/generators/named_base.rb +79 -3
  78. data/lib/rails/generators/rails/app/app_generator.rb +44 -209
  79. data/lib/rails/generators/rails/app/templates/Gemfile +15 -31
  80. data/lib/rails/generators/rails/app/templates/README +2 -2
  81. data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
  82. data/lib/rails/generators/rails/app/templates/{public → app/assets}/images/rails.png +0 -0
  83. data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +8 -0
  84. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -0
  85. data/lib/rails/generators/rails/app/templates/app/mailers/.empty_directory +0 -0
  86. data/lib/rails/generators/rails/app/templates/app/models/.empty_directory +0 -0
  87. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +4 -4
  88. data/lib/rails/generators/rails/app/templates/config/application.rb +19 -3
  89. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +4 -4
  90. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +11 -6
  91. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +3 -3
  92. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -1
  93. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -2
  94. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +14 -11
  95. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +5 -1
  96. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
  97. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +12 -0
  98. data/lib/rails/generators/rails/app/templates/config/locales/en.yml +1 -1
  99. data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
  100. data/lib/rails/generators/rails/app/templates/db/{seeds.rb → seeds.rb.tt} +2 -2
  101. data/lib/rails/generators/rails/app/templates/public/index.html +10 -8
  102. data/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  103. data/lib/rails/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
  104. data/lib/rails/generators/rails/app/templates/test/functional/.empty_directory +0 -0
  105. data/lib/rails/generators/rails/app/templates/test/integration/.empty_directory +0 -0
  106. data/lib/rails/generators/rails/app/templates/test/{test_helper.rb.tt → test_helper.rb} +0 -0
  107. data/lib/rails/generators/rails/app/templates/test/unit/.empty_directory +0 -0
  108. data/lib/rails/generators/rails/assets/USAGE +20 -0
  109. data/lib/rails/generators/rails/assets/assets_generator.rb +39 -0
  110. data/lib/rails/generators/rails/assets/templates/javascript.js +2 -0
  111. data/lib/rails/generators/rails/assets/templates/javascript.js.coffee +3 -0
  112. data/lib/rails/generators/rails/assets/templates/stylesheet.css +4 -0
  113. data/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +5 -0
  114. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  115. data/lib/rails/generators/rails/controller/templates/controller.rb +2 -0
  116. data/lib/rails/generators/rails/generator/generator_generator.rb +2 -2
  117. data/lib/rails/generators/rails/generator/templates/templates/.empty_directory +0 -0
  118. data/lib/rails/generators/rails/helper/templates/helper.rb +2 -0
  119. data/lib/rails/generators/rails/plugin/plugin_generator.rb +7 -0
  120. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +4 -4
  121. data/lib/rails/generators/rails/plugin_new/USAGE +10 -0
  122. data/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +303 -0
  123. data/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +9 -0
  124. data/lib/rails/generators/rails/plugin_new/templates/Gemfile +11 -0
  125. data/lib/rails/generators/rails/plugin_new/templates/MIT-LICENSE +20 -0
  126. data/lib/rails/generators/rails/plugin_new/templates/README.rdoc +3 -0
  127. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +21 -0
  128. data/lib/rails/generators/rails/plugin_new/templates/app/controllers/%name%/application_controller.rb.tt +4 -0
  129. data/lib/rails/generators/rails/plugin_new/templates/app/helpers/%name%/application_helper.rb.tt +4 -0
  130. data/lib/rails/generators/rails/plugin_new/templates/app/models/.empty_directory +0 -0
  131. data/lib/rails/generators/rails/plugin_new/templates/config/routes.rb +6 -0
  132. data/lib/rails/generators/rails/plugin_new/templates/gitignore +6 -0
  133. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%.rb +6 -0
  134. data/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb +7 -0
  135. data/lib/rails/generators/rails/plugin_new/templates/lib/tasks/%name%_tasks.rake +4 -0
  136. data/lib/rails/generators/rails/plugin_new/templates/rails/application.rb +16 -0
  137. data/lib/rails/generators/rails/plugin_new/templates/rails/boot.rb +10 -0
  138. data/lib/rails/generators/rails/plugin_new/templates/rails/routes.rb +4 -0
  139. data/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +5 -0
  140. data/lib/rails/generators/rails/plugin_new/templates/test/%name%_test.rb +7 -0
  141. data/lib/rails/generators/rails/plugin_new/templates/test/integration/navigation_test.rb +12 -0
  142. data/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +10 -0
  143. data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
  144. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +20 -1
  145. data/lib/rails/generators/rails/{stylesheets → scaffold}/templates/scaffold.css +0 -0
  146. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +58 -0
  147. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +21 -19
  148. data/lib/rails/generators/resource_helpers.rb +3 -3
  149. data/lib/rails/generators/test_case.rb +2 -20
  150. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +5 -4
  151. data/lib/rails/generators/test_unit/helper/templates/helper_test.rb +2 -0
  152. data/lib/rails/generators/test_unit/integration/templates/integration_test.rb +3 -4
  153. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +5 -4
  154. data/lib/rails/generators/test_unit/model/templates/fixtures.yml +1 -1
  155. data/lib/rails/generators/test_unit/model/templates/unit_test.rb +5 -4
  156. data/lib/rails/generators/test_unit/observer/templates/unit_test.rb +5 -4
  157. data/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +3 -4
  158. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb +7 -5
  159. data/lib/rails/info.rb +0 -1
  160. data/lib/rails/paths.rb +119 -65
  161. data/lib/rails/plugin.rb +18 -19
  162. data/lib/rails/rack/log_tailer.rb +1 -1
  163. data/lib/rails/railtie.rb +50 -47
  164. data/lib/rails/railtie/configurable.rb +20 -10
  165. data/lib/rails/railtie/configuration.rb +20 -19
  166. data/lib/rails/source_annotation_extractor.rb +5 -5
  167. data/lib/rails/tasks.rb +1 -0
  168. data/lib/rails/tasks/assets.rake +10 -0
  169. data/lib/rails/tasks/documentation.rake +2 -8
  170. data/lib/rails/tasks/engine.rake +69 -0
  171. data/lib/rails/tasks/framework.rake +4 -21
  172. data/lib/rails/tasks/misc.rake +1 -1
  173. data/lib/rails/tasks/routes.rake +2 -1
  174. data/lib/rails/test_help.rb +17 -1
  175. data/lib/rails/test_unit/railtie.rb +1 -1
  176. data/lib/rails/test_unit/testing.rake +8 -3
  177. data/lib/rails/version.rb +3 -3
  178. metadata +128 -100
  179. checksums.yaml +0 -7
  180. data/lib/rails/application/configurable.rb +0 -19
  181. data/lib/rails/console/sandbox.rb +0 -6
  182. data/lib/rails/deprecation.rb +0 -41
  183. data/lib/rails/engine/configurable.rb +0 -25
  184. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +0 -62
  185. data/lib/rails/generators/rails/app/templates/public/javascripts/application.js +0 -2
  186. data/lib/rails/generators/rails/app/templates/public/javascripts/controls.js +0 -965
  187. data/lib/rails/generators/rails/app/templates/public/javascripts/dragdrop.js +0 -974
  188. data/lib/rails/generators/rails/app/templates/public/javascripts/effects.js +0 -1123
  189. data/lib/rails/generators/rails/app/templates/public/javascripts/prototype.js +0 -6001
  190. data/lib/rails/generators/rails/app/templates/public/javascripts/rails.js +0 -202
  191. data/lib/rails/generators/rails/stylesheets/USAGE +0 -5
  192. data/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb +0 -9
  193. data/lib/rails/info_routes.rb +0 -3
data/CHANGELOG CHANGED
@@ -1,87 +1,74 @@
1
- ## Rails 3.0.20 (unreleased)
1
+ *Rails 3.1.0 (unreleased)*
2
2
 
3
- ## Rails 3.0.19 (Jan 8, 2013)
3
+ * The -j option of the application generator accepts an arbitrary string. If passed "foo",
4
+ the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest
5
+ requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails"
6
+ exist and provide those files via the asset pipeline. Default is "jquery". [fxn]
4
7
 
5
- * No changes.
8
+ * jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]
6
9
 
7
- ## Rails 3.0.18 (Jan 2, 2013)
10
+ * Prototype and Scriptaculous are no longer vendored, they are provided from now on
11
+ by the prototype-rails gem. [fxn]
8
12
 
9
- * No changes.
13
+ * The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]
10
14
 
11
- ## Rails 3.0.17 (Aug 9, 2012)
15
+ * The controller and resource generators will now automatically produce asset stubs (this can be turned off with --skip-assets). These stubs will use Coffee and Sass, if those libraries are available. [DHH]
12
16
 
13
- * No changes.
17
+ * jQuery is the new default JavaScript library. [fxn]
14
18
 
15
- ## Rails 3.0.16 (Jul 26, 2012)
19
+ * Changed scaffold and app generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist]
16
20
 
17
- * No changes.
21
+ So instead of creating something like:
18
22
 
19
- ## Rails 3.0.14 (Jun 12, 2012)
23
+ redirect_to users_path, :notice => "User has been created"
20
24
 
21
- * No changes.
25
+ it will now be like this:
22
26
 
23
- * Rails 3.0.13 (May 31, 2012)
27
+ redirect_to users_path, notice: "User has been created"
24
28
 
25
- * No changes.
29
+ You can also passing `--old-style-hash` to make Rails generate old style hash even you're on Ruby 1.9
26
30
 
27
- *Rails 3.0.11 (unreleased)*
31
+ * Changed scaffold_controller generator to create format block for JSON instead of XML [Prem Sichanugrist]
28
32
 
29
- * Updated Prototype UJS to lastest version fixing multiples errors in IE [Guillermo Iguaran]
33
+ * Add using Turn with natural language test case names for test_help.rb when running with minitest (Ruby 1.9.2+) [DHH]
30
34
 
35
+ * Direct logging of Active Record to STDOUT so it's shown inline with the results in the console [DHH]
31
36
 
32
- *Rails 3.0.10 (August 16, 2011)*
37
+ * Added `config.force_ssl` configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol [DHH, Prem Sichanugrist, and Josh Peek]
33
38
 
34
- *No changes.
39
+ * Added `rails plugin new` command which generates rails plugin with gemspec, tests and dummy application for testing [Piotr Sarnacki]
35
40
 
41
+ * Added -j parameter with jquery/prototype as options. Now you can create your apps with jQuery using `rails new myapp -j jquery`. The default is still Prototype. [siong1987]
36
42
 
37
- *Rails 3.0.9 (June 16, 2011)*
43
+ * Added Rack::Etag and Rack::ConditionalGet to the default middleware stack [José Valim]
38
44
 
39
- *No changes.
45
+ * Added Rack::Cache to the default middleware stack [Yehuda Katz and Carl Lerche]
40
46
 
47
+ * Engine is now rack application [Piotr Sarnacki]
41
48
 
42
- *Rails 3.0.8 (June 7, 2011)*
49
+ * Added middleware stack to Engine [Piotr Sarnacki]
43
50
 
44
- * Fix Rake 0.9.0 support.
51
+ * Engine can now load plugins [Piotr Sarnacki]
45
52
 
46
- *Rails 3.0.7 (April 18, 2011)*
53
+ * Engine can load its own environment file [Piotr Sarnacki]
47
54
 
48
- *No changes.
55
+ * Added helpers to call engines' route helpers from application and vice versa [Piotr Sarnacki]
49
56
 
57
+ * Task for copying plugins' and engines' migrations to application's db/migrate directory [Piotr Sarnacki]
50
58
 
51
- *Rails 3.0.6 (April 5, 2011)
59
+ * Changed ActionDispatch::Static to allow handling multiple directories [Piotr Sarnacki]
52
60
 
53
- * No changes.
54
-
55
-
56
- *Rails 3.0.5 (February 26, 2011)*
57
-
58
- * No changes.
59
-
60
-
61
- *Rails 3.0.4 (February 8, 2011)*
62
-
63
- * No changes.
64
-
65
-
66
- *Rails 3.0.3 (November 16, 2010)*
67
-
68
- * No changes.
69
-
70
-
71
- *Rails 3.0.2 (November 15, 2010)*
72
-
73
- * No changes.
61
+ * Added isolate_namespace() method to Engine, which sets Engine as isolated [Piotr Sarnacki]
74
62
 
63
+ * Include all helpers from plugins and shared engines in application [Piotr Sarnacki]
75
64
 
76
65
  *Rails 3.0.1 (October 15, 2010)*
77
66
 
78
- * No changes.
79
-
67
+ * No Changes, just a version bump.
80
68
 
81
69
  *Rails 3.0.0 (August 29, 2010)*
82
70
 
83
- * Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit
84
- and --skip-active-record respectively. [fxn]
71
+ * Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn]
85
72
 
86
73
  * Added console to Rails::Railtie as a hook called just after console starts. [José Valim]
87
74
 
@@ -4,7 +4,7 @@ Railties is responsible to glue all frameworks together. Overall, it:
4
4
 
5
5
  * handles all the bootstrapping process for a Rails application;
6
6
 
7
- * manager rails command line interface;
7
+ * manages rails command line interface;
8
8
 
9
9
  * provides Rails generators core;
10
10
 
@@ -23,3 +23,4 @@ Documentation can be found at
23
23
  == License
24
24
 
25
25
  Railties is released under the MIT license.
26
+
@@ -0,0 +1,16 @@
1
+ /*
2
+ Fix a rendering issue affecting WebKits on Mac.
3
+ See https://github.com/lifo/docrails/issues#issue/16 for more information.
4
+ */
5
+ .syntaxhighlighter a,
6
+ .syntaxhighlighter div,
7
+ .syntaxhighlighter code,
8
+ .syntaxhighlighter table,
9
+ .syntaxhighlighter table td,
10
+ .syntaxhighlighter table tr,
11
+ .syntaxhighlighter table tbody,
12
+ .syntaxhighlighter table thead,
13
+ .syntaxhighlighter table caption,
14
+ .syntaxhighlighter textarea {
15
+ line-height: 1.2em !important;
16
+ }
@@ -24,14 +24,14 @@ rescue LoadError
24
24
  end
25
25
 
26
26
  begin
27
- gem 'RedCloth', '>= 4.1.1'
28
27
  require 'redcloth'
29
28
  rescue Gem::LoadError
29
+ # This can happen if doc:guides is executed in an application.
30
30
  $stderr.puts('Generating guides requires RedCloth 4.1.1+.')
31
31
  $stderr.puts(<<ERROR) if bundler?
32
32
  Please add
33
33
 
34
- gem 'RedCloth', '>= 4.1.1'
34
+ gem 'RedCloth', '~> 4.2'
35
35
 
36
36
  to the Gemfile, run
37
37
 
@@ -32,12 +32,16 @@
32
32
  #
33
33
  # Separate many using commas:
34
34
  #
35
- # # generates only
35
+ # # generates only association_basics.html and migrations.html
36
36
  # ONLY=assoc,migrations ruby rails_guides.rb
37
37
  #
38
38
  # Note that if you are working on a guide generation will by default process
39
39
  # only that one, so ONLY is rarely used nowadays.
40
40
  #
41
+ # LANGUAGE
42
+ # Use LANGUAGE when you want to generate translated guides in <tt>source/<LANGUAGE></tt>
43
+ # folder (such as <tt>source/es</tt>). Ignore it when generating English guides.
44
+ #
41
45
  # EDGE
42
46
  # Set to "1" to indicate generated guides should be marked as edge. This
43
47
  # inserts a badge and changes the preamble of the home page.
@@ -63,6 +67,7 @@ module RailsGuides
63
67
  GUIDES_RE = /\.(?:textile|html\.erb)$/
64
68
 
65
69
  def initialize(output=nil)
70
+ @lang = ENV['LANGUAGE']
66
71
  initialize_dirs(output)
67
72
  create_output_dir_if_needed
68
73
  set_flags_from_environment
@@ -76,8 +81,8 @@ module RailsGuides
76
81
  private
77
82
  def initialize_dirs(output)
78
83
  @guides_dir = File.join(File.dirname(__FILE__), '..')
79
- @source_dir = File.join(@guides_dir, "source")
80
- @output_dir = output || File.join(@guides_dir, "output")
84
+ @source_dir = File.join(@guides_dir, "source", @lang.to_s)
85
+ @output_dir = output || File.join(@guides_dir, "output", @lang.to_s)
81
86
  end
82
87
 
83
88
  def create_output_dir_if_needed
@@ -1,9 +1,11 @@
1
+ require 'active_support/core_ext/object/inclusion'
2
+
1
3
  module RailsGuides
2
4
  module TextileExtensions
3
5
  def notestuff(body)
4
6
  body.gsub!(/^(IMPORTANT|CAUTION|WARNING|NOTE|INFO)[.:](.*)$/) do |m|
5
7
  css_class = $1.downcase
6
- css_class = 'warning' if ['caution', 'important'].include?(css_class)
8
+ css_class = 'warning' if css_class.in?(['caution', 'important'])
7
9
 
8
10
  result = "<div class='#{css_class}'><p>"
9
11
  result << $2.strip
@@ -33,7 +35,7 @@ module RailsGuides
33
35
  def code(body)
34
36
  body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
35
37
  es = ERB::Util.h($2)
36
- css_class = ['erb', 'shell'].include?($1) ? 'html' : $1
38
+ css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
37
39
  %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
38
40
  end
39
41
  end
@@ -260,15 +260,15 @@ h4. Other Action Controller Changes
260
260
  * Benchmarking numbers are now reported in milliseconds rather than tiny fractions of seconds
261
261
  * Rails now supports HTTP-only cookies (and uses them for sessions), which help mitigate some cross-site scripting risks in newer browsers.
262
262
  * +redirect_to+ now fully supports URI schemes (so, for example, you can redirect to a svn+ssh: URI).
263
- * +render+ now supports a +:js+ option to render plain vanilla javascript with the right mime type.
263
+ * +render+ now supports a +:js+ option to render plain vanilla JavaScript with the right mime type.
264
264
  * Request forgery protection has been tightened up to apply to HTML-formatted content requests only.
265
265
  * Polymorphic URLs behave more sensibly if a passed parameter is nil. For example, calling +polymorphic_path([@project, @date, @area])+ with a nil date will give you +project_area_path+.
266
266
 
267
267
  h3. Action View
268
268
 
269
269
  * +javascript_include_tag+ and +stylesheet_link_tag+ support a new +:recursive+ option to be used along with +:all+, so that you can load an entire tree of files with a single line of code.
270
- * The included Prototype javascript library has been upgraded to version 1.6.0.3.
271
- * +RJS#page.reload+ to reload the browser's current location via javascript
270
+ * The included Prototype JavaScript library has been upgraded to version 1.6.0.3.
271
+ * +RJS#page.reload+ to reload the browser's current location via JavaScript
272
272
  * The +atom_feed+ helper now takes an +:instruct+ option to let you insert XML processing instructions.
273
273
 
274
274
  h3. Action Mailer
@@ -278,7 +278,7 @@ Mime::JS =~ "text/javascript" => true
278
278
  Mime::JS =~ "application/javascript" => true
279
279
  </ruby>
280
280
 
281
- The other change is that the framework now uses the +Mime::JS+ when checking for javascript in various spots, making it handle those alternatives cleanly.
281
+ The other change is that the framework now uses the +Mime::JS+ when checking for JavaScript in various spots, making it handle those alternatives cleanly.
282
282
 
283
283
  * Lead Contributor: "Seth Fitzsimmons":http://www.workingwithrails.com/person/5510-seth-fitzsimmons
284
284
 
@@ -410,7 +410,7 @@ You're likely familiar with Rails' practice of adding timestamps to static asset
410
410
 
411
411
  h4. Asset Hosts as Objects
412
412
 
413
- Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to to implement any complex logic you need in your asset hosting.
413
+ Asset hosts get more flexible in edge Rails with the ability to declare an asset host as a specific object that responds to a call. This allows you to implement any complex logic you need in your asset hosting.
414
414
 
415
415
  * More Information: "asset-hosting-with-minimum-ssl":http://github.com/dhh/asset-hosting-with-minimum-ssl/tree/master
416
416
 
@@ -22,7 +22,7 @@ To install Rails 3:
22
22
 
23
23
  <shell>
24
24
  # Use sudo if your setup requires it
25
- gem install rails
25
+ $ gem install rails
26
26
  </shell>
27
27
 
28
28
 
@@ -47,8 +47,8 @@ h4. script/* replaced by script/rails
47
47
  The new <tt>script/rails</tt> replaces all the scripts that used to be in the <tt>script</tt> directory. You do not run <tt>script/rails</tt> 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:
48
48
 
49
49
  <shell>
50
- rails console # instead of script/console
51
- rails g scaffold post title:string # instead of script/generate scaffold post title:string
50
+ $ rails console # instead of script/console
51
+ $ rails g scaffold post title:string # instead of script/generate scaffold post title:string
52
52
  </shell>
53
53
 
54
54
  Run <tt>rails --help</tt> for a list of all the options.
@@ -59,12 +59,12 @@ The +config.gem+ method is gone and has been replaced by using +bundler+ and a +
59
59
 
60
60
  h4. Upgrade Process
61
61
 
62
- To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/rails/rails_upgrade has been created to automate part of it.
62
+ To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it.
63
63
 
64
64
  Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following:
65
65
 
66
66
  <shell>
67
- ruby script/plugin install git://github.com/rails/rails_upgrade.git
67
+ $ ruby script/plugin install git://github.com/jm/rails_upgrade.git
68
68
  </shell>
69
69
 
70
70
  You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin
@@ -357,15 +357,15 @@ Validations have been moved from Active Record into Active Model, providing an i
357
357
 
358
358
  * There is now a <tt>validates :attribute, options_hash</tt> shortcut method that allows you to pass options for all the validates class methods, you can pass more than one option to a validate method.
359
359
  * The +validates+ method has the following options:
360
- * <tt>:acceptance => Boolean</tt>.
361
- * <tt>:confirmation => Boolean</tt>.
362
- * <tt>:exclusion => { :in => Enumerable }</tt>.
363
- * <tt>:inclusion => { :in => Enumerable }</tt>.
364
- * <tt>:format => { :with => Regexp, :on => :create }</tt>.
365
- * <tt>:length => { :maximum => Fixnum }</tt>.
366
- * <tt>:numericality => Boolean</tt>.
367
- * <tt>:presence => Boolean</tt>.
368
- * <tt>:uniqueness => Boolean</tt>.
360
+ ** <tt>:acceptance => Boolean</tt>.
361
+ ** <tt>:confirmation => Boolean</tt>.
362
+ ** <tt>:exclusion => { :in => Enumerable }</tt>.
363
+ ** <tt>:inclusion => { :in => Enumerable }</tt>.
364
+ ** <tt>:format => { :with => Regexp, :on => :create }</tt>.
365
+ ** <tt>:length => { :maximum => Fixnum }</tt>.
366
+ ** <tt>:numericality => Boolean</tt>.
367
+ ** <tt>:presence => Boolean</tt>.
368
+ ** <tt>:uniqueness => Boolean</tt>.
369
369
 
370
370
  NOTE: All the Rails version 2.3 style validation methods are still supported in Rails 3.0, the new validates method is designed as an additional aid in your model validations, not a replacement for the existing API.
371
371
 
@@ -98,7 +98,7 @@ The value of +params[:ids]+ will now be +["1", "2", "3"]+. Note that parameter v
98
98
  To send a hash you include the key name inside the brackets:
99
99
 
100
100
  <html>
101
- <form action="/clients" method="post">
101
+ <form accept-charset="UTF-8" action="/clients" method="post">
102
102
  <input type="text" name="client[name]" value="Acme" />
103
103
  <input type="text" name="client[phone]" value="12345" />
104
104
  <input type="text" name="client[address][postcode]" value="12345" />
@@ -115,10 +115,7 @@ h4. Routing Parameters
115
115
  The +params+ hash will always contain the +:controller+ and +:action+ keys, but you should use the methods +controller_name+ and +action_name+ instead to access these values. Any other parameters defined by the routing, such as +:id+ will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the +:status+ parameter in a "pretty" URL:
116
116
 
117
117
  <ruby>
118
- map.connect "/clients/:status",
119
- :controller => "clients",
120
- :action => "index",
121
- :foo => "bar"
118
+ match '/clients/:status' => 'clients#index', :foo => "bar"
122
119
  </ruby>
123
120
 
124
121
  In this case, when a user opens the URL +/clients/active+, +params[:status]+ will be set to "active". When this route is used, +params[:foo]+ will also be set to "bar" just like it was passed in the query string. In the same way +params[:action]+ will contain "index".
@@ -161,7 +158,7 @@ If you need a different session storage mechanism, you can change it in the +con
161
158
  <ruby>
162
159
  # Use the database for sessions instead of the cookie-based default,
163
160
  # which shouldn't be used to store highly confidential information
164
- # (create the session table with "rake db:sessions:create")
161
+ # (create the session table with "script/rails g session_migration")
165
162
  # YourApp::Application.config.session_store :active_record_store
166
163
  </ruby>
167
164
 
@@ -214,7 +211,7 @@ class ApplicationController < ActionController::Base
214
211
  # logging out removes it.
215
212
  def current_user
216
213
  @_current_user ||= session[:current_user_id] &&
217
- User.find(session[:current_user_id])
214
+ User.find_by_id(session[:current_user_id])
218
215
  end
219
216
  end
220
217
  </ruby>
@@ -371,6 +368,7 @@ class UsersController < ApplicationController
371
368
  respond_to do |format|
372
369
  format.html # index.html.erb
373
370
  format.xml { render :xml => @users}
371
+ format.json { render :json => @users}
374
372
  end
375
373
  end
376
374
  end
@@ -425,27 +423,36 @@ Now, the +LoginsController+'s +new+ and +create+ actions will work as before wit
425
423
 
426
424
  h4. After Filters and Around Filters
427
425
 
428
- In addition to before filters, you can run filters after an action has run or both before and after. The after filter is similar to the before filter, but because the action has already been run it has access to the response data that's about to be sent to the client. Obviously, after filters can not stop the action from running.
426
+ In addition to before filters, you can also run filters after an action has been executed, or both before and after.
429
427
 
430
- Around filters are responsible for running the action, but they can choose not to, which is the around filter's way of stopping it.
428
+ After filters are similar to before filters, but because the action has already been run they have access to the response data that's about to be sent to the client. Obviously, after filters cannot stop the action from running.
429
+
430
+ Around filters are responsible for running their associated actions by yielding, similar to how Rack middlewares work.
431
+
432
+ For example, in a website where changes have an approval workflow an administrator could be able to preview them easily, just apply them within a transaction:
431
433
 
432
434
  <ruby>
433
- # Example taken from the Rails API filter documentation:
434
- # http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
435
- class ApplicationController < ActionController::Base
436
- around_filter :catch_exceptions
435
+ class ChangesController < ActionController::Base
436
+ around_filter :wrap_in_transaction, :only => :show
437
437
 
438
438
  private
439
439
 
440
- def catch_exceptions
441
- yield
442
- rescue => exception
443
- logger.debug "Caught exception! #{exception}"
444
- raise
440
+ def wrap_in_transaction
441
+ ActiveRecord::Base.transaction do
442
+ begin
443
+ yield
444
+ ensure
445
+ raise ActiveRecord::Rollback
446
+ end
447
+ end
445
448
  end
446
449
  end
447
450
  </ruby>
448
451
 
452
+ Note that an around filter wraps also rendering. In particular, if in the example above the view itself reads from the database via a scope or whatever, it will do so within the transaction and thus present the data to preview.
453
+
454
+ They can choose not to yield and build the response themselves, in which case the action is not run.
455
+
449
456
  h4. Other Ways to Use Filters
450
457
 
451
458
  While the most common way to use filters is by creating private methods and using *_filter to add them, there are two other ways to do the same thing.
@@ -481,45 +488,6 @@ end
481
488
 
482
489
  Again, this is not an ideal example for this filter, because it's not run in the scope of the controller but gets the controller passed as an argument. The filter class has a class method +filter+ which gets run before or after the action, depending on if it's a before or after filter. Classes used as around filters can also use the same +filter+ method, which will get run in the same way. The method must +yield+ to execute the action. Alternatively, it can have both a +before+ and an +after+ method that are run before and after the action.
483
490
 
484
- h3. Verification
485
-
486
- Verifications make sure certain criteria are met in order for a controller or action to run. They can specify that a certain key (or several keys in the form of an array) is present in the +params+, +session+ or +flash+ hashes or that a certain HTTP method was used or that the request was made using +XMLHttpRequest+ (Ajax). The default action taken when these criteria are not met is to render a 400 Bad Request response, but you can customize this by specifying a redirect URL or rendering something else and you can also add flash messages and HTTP headers to the response. It is described in the "API documentation":http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html as "essentially a special kind of before_filter".
487
-
488
- Here's an example of using verification to make sure the user supplies a username and a password in order to log in:
489
-
490
- <ruby>
491
- class LoginsController < ApplicationController
492
- verify :params => [:username, :password],
493
- :render => {:action => "new"},
494
- :add_flash => {
495
- :error => "Username and password required to log in"
496
- }
497
-
498
- def create
499
- @user = User.authenticate(params[:username], params[:password])
500
- if @user
501
- flash[:notice] = "You're logged in"
502
- redirect_to root_url
503
- else
504
- render :action => "new"
505
- end
506
- end
507
- end
508
- </ruby>
509
-
510
- Now the +create+ action won't run unless the "username" and "password" parameters are present, and if they're not, an error message will be added to the flash and the +new+ action will be rendered. But there's something rather important missing from the verification above: It will be used for *every* action in LoginsController, which is not what we want. You can limit which actions it will be used for with the +:only+ and +:except+ options just like a filter:
511
-
512
- <ruby>
513
- class LoginsController < ApplicationController
514
- verify :params => [:username, :password],
515
- :render => {:action => "new"},
516
- :add_flash => {
517
- :error => "Username and password required to log in"
518
- },
519
- :only => :create # Run only for the "create" action
520
- end
521
- </ruby>
522
-
523
491
  h3. Request Forgery Protection
524
492
 
525
493
  Cross-site request forgery is a type of attack in which a site tricks a user into making requests on another site, possibly adding, modifying or deleting data on that site without the user's knowledge or permission.
@@ -540,7 +508,7 @@ If you generate a form like this:
540
508
  You will see how the token gets added as a hidden field:
541
509
 
542
510
  <html>
543
- <form action="/users/1" method="post">
511
+ <form accept-charset="UTF-8" action="/users/1" method="post">
544
512
  <input type="hidden"
545
513
  value="67250ab105eb5ad10851c00a5621854a23af5489"
546
514
  name="authenticity_token"/>
@@ -560,7 +528,7 @@ In every controller there are two accessor methods pointing to the request and t
560
528
 
561
529
  h4. The +request+ Object
562
530
 
563
- The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the "API documentation":http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html. Among the properties that you can access on this object are:
531
+ The request object contains a lot of useful information about the request coming in from the client. To get a full list of the available methods, refer to the "API documentation":http://api.rubyonrails.org/classes/ActionDispatch/Request.html. Among the properties that you can access on this object are:
564
532
 
565
533
  |_.Property of +request+|_.Purpose|
566
534
  |host|The hostname used for this request.|
@@ -608,26 +576,15 @@ Rails comes with two built-in HTTP authentication mechanisms:
608
576
 
609
577
  h4. HTTP Basic Authentication
610
578
 
611
- HTTP basic authentication is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, +authenticate_or_request_with_http_basic+.
579
+ HTTP basic authentication is an authentication scheme that is supported by the majority of browsers and other HTTP clients. As an example, consider an administration section which will only be available by entering a username and a password into the browser's HTTP basic dialog window. Using the built-in authentication is quite easy and only requires you to use one method, +http_basic_authenticate_with+.
612
580
 
613
581
  <ruby>
614
582
  class AdminController < ApplicationController
615
- USERNAME, PASSWORD = "humbaba", "5baa61e4"
616
-
617
- before_filter :authenticate
618
-
619
- private
620
-
621
- def authenticate
622
- authenticate_or_request_with_http_basic do |username, password|
623
- username == USERNAME &&
624
- Digest::SHA1.hexdigest(password) == PASSWORD
625
- end
626
- end
583
+ http_basic_authenticate_with :name => "humbaba", :password => "5baa61e4"
627
584
  end
628
585
  </ruby>
629
586
 
630
- With this in place, you can create namespaced controllers that inherit from +AdminController+. The before filter will thus be run for all actions in those controllers, protecting them with HTTP basic authentication.
587
+ With this in place, you can create namespaced controllers that inherit from +AdminController+. The filter will thus be run for all actions in those controllers, protecting them with HTTP basic authentication.
631
588
 
632
589
  h4. HTTP Digest Authentication
633
590
 
@@ -739,16 +696,12 @@ GET /clients/1.pdf
739
696
 
740
697
  h3. Parameter Filtering
741
698
 
742
- Rails keeps a log file for each environment in the +log+ folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. The +filter_parameter_logging+ method can be used to filter out sensitive information from the log. It works by replacing certain values in the +params+ hash with "[FILTERED]" as they are written to the log. As an example, let's see how to filter all parameters with keys that include "password":
699
+ Rails keeps a log file for each environment in the +log+ folder. These are extremely useful when debugging what's actually going on in your application, but in a live application you may not want every bit of information to be stored in the log file. You can filter certain request parameters from your log files by appending them to <tt>config.filter_parameters</tt> in the application configuration. These parameters will be marked [FILTERED] in the log.
743
700
 
744
701
  <ruby>
745
- class ApplicationController < ActionController::Base
746
- filter_parameter_logging :password
747
- end
702
+ config.filter_parameters << :password
748
703
  </ruby>
749
704
 
750
- The method works recursively through all levels of the +params+ hash and takes an optional second parameter which is used as the replacement string if present. It can also take a block which receives each key in turn and replaces those for which the block returns true.
751
-
752
705
  h3. Rescue
753
706
 
754
707
  Most likely your application is going to contain bugs or otherwise throw an exception that needs to be handled. For example, if the user follows a link to a resource that no longer exists in the database, Active Record will throw the +ActiveRecord::RecordNotFound+ exception.
@@ -813,6 +766,28 @@ end
813
766
 
814
767
  NOTE: Certain exceptions are only rescuable from the +ApplicationController+ class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's "article":http://m.onkey.org/2008/7/20/rescue-from-dispatching on the subject for more information.
815
768
 
769
+ h3. Force HTTPS protocol
770
+
771
+ Sometime you might want to force a particular controller to only be accessible via an HTTPS protocol for security reason. Since Rails 3.1 you can now use +force_ssl+ method in your controller to enforce that:
772
+
773
+ <ruby>
774
+ class DinnerController
775
+ force_ssl
776
+ end
777
+ </ruby>
778
+
779
+ Just like the filter, you could also passing +:only+ and +:except+ to enforce the secure connection only to specific actions
780
+
781
+ <ruby>
782
+ class DinnerController
783
+ force_ssl :only => :cheeseburger
784
+ # or
785
+ force_ssl :except => :cheeseburger
786
+ end
787
+ </ruby>
788
+
789
+ Please note that if you found yourself adding +force_ssl+ to many controllers, you may found yourself wanting to force the whole application to use HTTPS instead. In that case, you can set the +config.force_ssl+ in your environment file.
790
+
816
791
  h3. Changelog
817
792
 
818
793
  * February 17, 2009: Yet another proofread by Xavier Noria.