rails 4.1.6 → 4.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +12 -10
  3. data/guides/CHANGELOG.md +64 -17
  4. data/guides/Rakefile +21 -6
  5. data/guides/assets/images/getting_started/article_with_comments.png +0 -0
  6. data/guides/assets/javascripts/guides.js +6 -0
  7. data/guides/assets/stylesheets/main.css +4 -1
  8. data/guides/bug_report_templates/action_controller_gem.rb +3 -3
  9. data/guides/bug_report_templates/action_controller_master.rb +3 -2
  10. data/guides/bug_report_templates/active_record_gem.rb +1 -1
  11. data/guides/bug_report_templates/generic_gem.rb +15 -0
  12. data/guides/bug_report_templates/generic_master.rb +26 -0
  13. data/guides/rails_guides/helpers.rb +1 -1
  14. data/guides/rails_guides/levenshtein.rb +27 -21
  15. data/guides/rails_guides/markdown/renderer.rb +1 -1
  16. data/guides/rails_guides/markdown.rb +11 -7
  17. data/guides/rails_guides.rb +2 -2
  18. data/guides/source/2_2_release_notes.md +1 -1
  19. data/guides/source/2_3_release_notes.md +4 -4
  20. data/guides/source/3_0_release_notes.md +8 -8
  21. data/guides/source/3_1_release_notes.md +6 -3
  22. data/guides/source/3_2_release_notes.md +6 -3
  23. data/guides/source/4_0_release_notes.md +6 -3
  24. data/guides/source/4_1_release_notes.md +9 -10
  25. data/guides/source/4_2_release_notes.md +877 -0
  26. data/guides/source/_license.html.erb +1 -1
  27. data/guides/source/_welcome.html.erb +6 -8
  28. data/guides/source/action_controller_overview.md +25 -8
  29. data/guides/source/action_mailer_basics.md +97 -29
  30. data/guides/source/action_view_overview.md +142 -191
  31. data/guides/source/active_job_basics.md +339 -0
  32. data/guides/source/active_model_basics.md +371 -17
  33. data/guides/source/active_record_basics.md +25 -24
  34. data/guides/source/active_record_callbacks.md +12 -9
  35. data/guides/source/{migrations.md → active_record_migrations.md} +95 -220
  36. data/guides/source/active_record_postgresql.md +433 -0
  37. data/guides/source/active_record_querying.md +264 -268
  38. data/guides/source/active_record_validations.md +23 -13
  39. data/guides/source/active_support_core_extensions.md +115 -123
  40. data/guides/source/active_support_instrumentation.md +10 -18
  41. data/guides/source/api_documentation_guidelines.md +63 -17
  42. data/guides/source/asset_pipeline.md +259 -120
  43. data/guides/source/association_basics.md +96 -80
  44. data/guides/source/autoloading_and_reloading_constants.md +1311 -0
  45. data/guides/source/caching_with_rails.md +32 -7
  46. data/guides/source/command_line.md +52 -30
  47. data/guides/source/configuring.md +161 -33
  48. data/guides/source/contributing_to_ruby_on_rails.md +198 -114
  49. data/guides/source/credits.html.erb +2 -2
  50. data/guides/source/debugging_rails_applications.md +440 -286
  51. data/guides/source/development_dependencies_install.md +47 -36
  52. data/guides/source/documents.yaml +19 -7
  53. data/guides/source/engines.md +217 -196
  54. data/guides/source/form_helpers.md +79 -56
  55. data/guides/source/generators.md +24 -11
  56. data/guides/source/getting_started.md +359 -219
  57. data/guides/source/i18n.md +110 -66
  58. data/guides/source/index.html.erb +1 -0
  59. data/guides/source/initialization.md +109 -62
  60. data/guides/source/layout.html.erb +5 -11
  61. data/guides/source/layouts_and_rendering.md +26 -26
  62. data/guides/source/maintenance_policy.md +6 -3
  63. data/guides/source/nested_model_forms.md +7 -4
  64. data/guides/source/plugins.md +27 -27
  65. data/guides/source/rails_application_templates.md +21 -3
  66. data/guides/source/rails_on_rack.md +8 -5
  67. data/guides/source/routing.md +113 -73
  68. data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
  69. data/guides/source/security.md +40 -34
  70. data/guides/source/testing.md +199 -119
  71. data/guides/source/upgrading_ruby_on_rails.md +289 -31
  72. data/guides/source/working_with_javascript_in_rails.md +19 -17
  73. data/guides/w3c_validator.rb +2 -0
  74. metadata +42 -95
  75. data/guides/code/getting_started/Gemfile +0 -40
  76. data/guides/code/getting_started/Gemfile.lock +0 -125
  77. data/guides/code/getting_started/README.rdoc +0 -28
  78. data/guides/code/getting_started/Rakefile +0 -6
  79. data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
  80. data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
  81. data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
  82. data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
  83. data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
  84. data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
  85. data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
  86. data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
  87. data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
  88. data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
  89. data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
  90. data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
  91. data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
  92. data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
  93. data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
  94. data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
  95. data/guides/code/getting_started/app/models/comment.rb +0 -3
  96. data/guides/code/getting_started/app/models/post.rb +0 -7
  97. data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
  98. data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
  99. data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
  100. data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
  101. data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
  102. data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
  103. data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
  104. data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
  105. data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
  106. data/guides/code/getting_started/bin/bundle +0 -4
  107. data/guides/code/getting_started/bin/rails +0 -4
  108. data/guides/code/getting_started/bin/rake +0 -4
  109. data/guides/code/getting_started/config/application.rb +0 -18
  110. data/guides/code/getting_started/config/boot.rb +0 -4
  111. data/guides/code/getting_started/config/database.yml +0 -25
  112. data/guides/code/getting_started/config/environment.rb +0 -5
  113. data/guides/code/getting_started/config/environments/development.rb +0 -30
  114. data/guides/code/getting_started/config/environments/production.rb +0 -80
  115. data/guides/code/getting_started/config/environments/test.rb +0 -36
  116. data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
  117. data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
  118. data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
  119. data/guides/code/getting_started/config/initializers/locale.rb +0 -9
  120. data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
  121. data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
  122. data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
  123. data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
  124. data/guides/code/getting_started/config/locales/en.yml +0 -23
  125. data/guides/code/getting_started/config/routes.rb +0 -7
  126. data/guides/code/getting_started/config.ru +0 -4
  127. data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
  128. data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
  129. data/guides/code/getting_started/db/schema.rb +0 -33
  130. data/guides/code/getting_started/db/seeds.rb +0 -7
  131. data/guides/code/getting_started/public/404.html +0 -60
  132. data/guides/code/getting_started/public/422.html +0 -60
  133. data/guides/code/getting_started/public/500.html +0 -59
  134. data/guides/code/getting_started/public/favicon.ico +0 -0
  135. data/guides/code/getting_started/public/robots.txt +0 -5
  136. data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
  137. data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
  138. data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
  139. data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
  140. data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
  141. data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
  142. data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
  143. data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
  144. data/guides/code/getting_started/test/models/comment_test.rb +0 -7
  145. data/guides/code/getting_started/test/models/post_test.rb +0 -7
  146. data/guides/code/getting_started/test/test_helper.rb +0 -12
@@ -98,9 +98,9 @@ configure the load path for your Gemfile's dependencies.
98
98
 
99
99
  A standard Rails application depends on several gems, specifically:
100
100
 
101
- * abstract
102
101
  * actionmailer
103
102
  * actionpack
103
+ * actionview
104
104
  * activemodel
105
105
  * activerecord
106
106
  * activesupport
@@ -111,7 +111,6 @@ A standard Rails application depends on several gems, specifically:
111
111
  * i18n
112
112
  * mail
113
113
  * mime-types
114
- * polyglot
115
114
  * rack
116
115
  * rack-cache
117
116
  * rack-mount
@@ -119,9 +118,8 @@ A standard Rails application depends on several gems, specifically:
119
118
  * rails
120
119
  * railties
121
120
  * rake
122
- * sqlite3-ruby
121
+ * sqlite3
123
122
  * thor
124
- * treetop
125
123
  * tzinfo
126
124
 
127
125
  ### `rails/commands.rb`
@@ -163,9 +161,10 @@ throwing an error message. If the command is valid, a method of the same name
163
161
  is called.
164
162
 
165
163
  ```ruby
166
- COMMAND_WHITELIST = %(plugin generate destroy console server dbconsole application runner new version help)
164
+ COMMAND_WHITELIST = %w(plugin generate destroy console server dbconsole application runner new version help)
167
165
 
168
166
  def run_command!(command)
167
+ command = parse_command(command)
169
168
  if COMMAND_WHITELIST.include?(command)
170
169
  send(command)
171
170
  else
@@ -178,8 +177,7 @@ With the `server` command, Rails will further run the following code:
178
177
 
179
178
  ```ruby
180
179
  def set_application_directory!
181
- Dir.chdir(File.expand_path('../../', APP_PATH)) unless
182
- File.exist?(File.expand_path("config.ru"))
180
+ Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
183
181
  end
184
182
 
185
183
  def server
@@ -187,6 +185,8 @@ def server
187
185
  require_command!("server")
188
186
 
189
187
  Rails::Server.new.tap do |server|
188
+ # We need to require application after the server sets environment,
189
+ # otherwise the --environment option given to the server won't propagate.
190
190
  require APP_PATH
191
191
  Dir.chdir(Rails.application.root)
192
192
  server.start
@@ -207,6 +207,7 @@ sets up the `Rails::Server` class.
207
207
  require 'fileutils'
208
208
  require 'optparse'
209
209
  require 'action_dispatch'
210
+ require 'rails'
210
211
 
211
212
  module Rails
212
213
  class Server < ::Rack::Server
@@ -273,7 +274,7 @@ def parse_options(args)
273
274
  # http://www.meb.uni-bonn.de/docs/cgi/cl.html
274
275
  args.clear if ENV.include?("REQUEST_METHOD")
275
276
 
276
- options.merge! opt_parser.parse! args
277
+ options.merge! opt_parser.parse!(args)
277
278
  options[:config] = ::File.expand_path(options[:config])
278
279
  ENV["RACK_ENV"] = options[:environment]
279
280
  options
@@ -284,18 +285,21 @@ With the `default_options` set to this:
284
285
 
285
286
  ```ruby
286
287
  def default_options
288
+ environment = ENV['RACK_ENV'] || 'development'
289
+ default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
290
+
287
291
  {
288
- environment: ENV['RACK_ENV'] || "development",
289
- pid: nil,
290
- Port: 9292,
291
- Host: "0.0.0.0",
292
- AccessLog: [],
293
- config: "config.ru"
292
+ :environment => environment,
293
+ :pid => nil,
294
+ :Port => 9292,
295
+ :Host => default_host,
296
+ :AccessLog => [],
297
+ :config => "config.ru"
294
298
  }
295
299
  end
296
300
  ```
297
301
 
298
- There is no `REQUEST_METHOD` key in `ENV` so we can skip over that line. The next line merges in the options from `opt_parser` which is defined plainly in `Rack::Server`
302
+ There is no `REQUEST_METHOD` key in `ENV` so we can skip over that line. The next line merges in the options from `opt_parser` which is defined plainly in `Rack::Server`:
299
303
 
300
304
  ```ruby
301
305
  def opt_parser
@@ -348,6 +352,7 @@ private
348
352
  def print_boot_information
349
353
  ...
350
354
  puts "=> Run `rails server -h` for more startup options"
355
+ ...
351
356
  puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
352
357
  end
353
358
 
@@ -434,7 +439,11 @@ The `app` method here is defined like so:
434
439
 
435
440
  ```ruby
436
441
  def app
437
- @app ||= begin
442
+ @app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
443
+ end
444
+ ...
445
+ private
446
+ def build_app_and_options_from_config
438
447
  if !::File.exist? options[:config]
439
448
  abort "configuration #{options[:config]} not found"
440
449
  end
@@ -443,7 +452,10 @@ def app
443
452
  self.options.merge! options
444
453
  app
445
454
  end
446
- end
455
+
456
+ def build_app_from_string
457
+ Rack::Builder.new_from_string(self.options[:builder])
458
+ end
447
459
  ```
448
460
 
449
461
  The `options[:config]` value defaults to `config.ru` which contains this:
@@ -459,8 +471,14 @@ run <%= app_const %>
459
471
  The `Rack::Builder.parse_file` method here takes the content from this `config.ru` file and parses it using this code:
460
472
 
461
473
  ```ruby
462
- app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
463
- TOPLEVEL_BINDING, config
474
+ app = new_from_string cfgfile, config
475
+
476
+ ...
477
+
478
+ def self.new_from_string(builder_script, file="(rackup)")
479
+ eval "Rack::Builder.new {\n" + builder_script + "\n}.to_app",
480
+ TOPLEVEL_BINDING, file, 0
481
+ end
464
482
  ```
465
483
 
466
484
  The `initialize` method of `Rack::Builder` will take the block here and execute it within an instance of `Rack::Builder`. This is where the majority of the initialization process of Rails happens. The `require` line for `config/environment.rb` in `config.ru` is the first to run:
@@ -473,11 +491,22 @@ require ::File.expand_path('../config/environment', __FILE__)
473
491
 
474
492
  This file is the common file required by `config.ru` (`rails server`) and Passenger. This is where these two ways to run the server meet; everything before this point has been Rack and Rails setup.
475
493
 
476
- This file begins with requiring `config/application.rb`.
494
+ This file begins with requiring `config/application.rb`:
495
+
496
+ ```ruby
497
+ require File.expand_path('../application', __FILE__)
498
+ ```
477
499
 
478
500
  ### `config/application.rb`
479
501
 
480
- This file requires `config/boot.rb`, but only if it hasn't been required before, which would be the case in `rails server` but **wouldn't** be the case with Passenger.
502
+ This file requires `config/boot.rb`:
503
+
504
+ ```ruby
505
+ require File.expand_path('../boot', __FILE__)
506
+ ```
507
+
508
+ But only if it hasn't been required before, which would be the case in `rails server`
509
+ but **wouldn't** be the case with Passenger.
481
510
 
482
511
  Then the fun begins!
483
512
 
@@ -498,11 +527,12 @@ This file is responsible for requiring all the individual frameworks of Rails:
498
527
  require "rails"
499
528
 
500
529
  %w(
501
- active_record
502
- action_controller
503
- action_mailer
504
- rails/test_unit
505
- sprockets
530
+ active_record
531
+ action_controller
532
+ action_view
533
+ action_mailer
534
+ rails/test_unit
535
+ sprockets
506
536
  ).each do |framework|
507
537
  begin
508
538
  require "#{framework}/railtie"
@@ -527,7 +557,7 @@ initialized. When `config/application.rb` has finished loading Rails and defined
527
557
  the application namespace, we go back to `config/environment.rb`,
528
558
  where the application is initialized. For example, if the application was called
529
559
  `Blog`, here we would find `Rails.application.initialize!`, which is
530
- defined in `rails/application.rb`
560
+ defined in `rails/application.rb`.
531
561
 
532
562
  ### `railties/lib/rails/application.rb`
533
563
 
@@ -543,7 +573,7 @@ end
543
573
  ```
544
574
 
545
575
  As you can see, you can only initialize an app once. The initializers are run through
546
- the `run_initializers` method which is defined in `railties/lib/rails/initializable.rb`
576
+ the `run_initializers` method which is defined in `railties/lib/rails/initializable.rb`:
547
577
 
548
578
  ```ruby
549
579
  def run_initializers(group=:default, *args)
@@ -555,7 +585,7 @@ def run_initializers(group=:default, *args)
555
585
  end
556
586
  ```
557
587
 
558
- The run_initializers code itself is tricky. What Rails is doing here is
588
+ The `run_initializers` code itself is tricky. What Rails is doing here is
559
589
  traversing all the class ancestors looking for those that respond to an
560
590
  `initializers` method. It then sorts the ancestors by name, and runs them.
561
591
  For example, the `Engine` class will make all the engines available by
@@ -568,7 +598,7 @@ initializers (like building the middleware stack) are run last. The `railtie`
568
598
  initializers are the initializers which have been defined on the `Rails::Application`
569
599
  itself and are run between the `bootstrap` and `finishers`.
570
600
 
571
- After this is done we go back to `Rack::Server`
601
+ After this is done we go back to `Rack::Server`.
572
602
 
573
603
  ### Rack: lib/rack/server.rb
574
604
 
@@ -576,7 +606,11 @@ Last time we left when the `app` method was being defined:
576
606
 
577
607
  ```ruby
578
608
  def app
579
- @app ||= begin
609
+ @app ||= options[:builder] ? build_app_from_string : build_app_and_options_from_config
610
+ end
611
+ ...
612
+ private
613
+ def build_app_and_options_from_config
580
614
  if !::File.exist? options[:config]
581
615
  abort "configuration #{options[:config]} not found"
582
616
  end
@@ -585,7 +619,10 @@ def app
585
619
  self.options.merge! options
586
620
  app
587
621
  end
588
- end
622
+
623
+ def build_app_from_string
624
+ Rack::Builder.new_from_string(self.options[:builder])
625
+ end
589
626
  ```
590
627
 
591
628
  At this point `app` is the Rails app itself (a middleware), and what
@@ -603,7 +640,7 @@ def build_app(app)
603
640
  end
604
641
  ```
605
642
 
606
- Remember, `build_app` was called (by wrapped_app) in the last line of `Server#start`.
643
+ Remember, `build_app` was called (by `wrapped_app`) in the last line of `Server#start`.
607
644
  Here's how it looked like when we left:
608
645
 
609
646
  ```ruby
@@ -611,40 +648,50 @@ server.run wrapped_app, options, &blk
611
648
  ```
612
649
 
613
650
  At this point, the implementation of `server.run` will depend on the
614
- server you're using. For example, if you were using Mongrel, here's what
651
+ server you're using. For example, if you were using Puma, here's what
615
652
  the `run` method would look like:
616
653
 
617
654
  ```ruby
618
- def self.run(app, options={})
619
- server = ::Mongrel::HttpServer.new(
620
- options[:Host] || '0.0.0.0',
621
- options[:Port] || 8080,
622
- options[:num_processors] || 950,
623
- options[:throttle] || 0,
624
- options[:timeout] || 60)
625
- # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
626
- # Use is similar to #run, replacing the app argument with a hash of
627
- # { path=>app, ... } or an instance of Rack::URLMap.
628
- if options[:map]
629
- if app.is_a? Hash
630
- app.each do |path, appl|
631
- path = '/'+path unless path[0] == ?/
632
- server.register(path, Rack::Handler::Mongrel.new(appl))
633
- end
634
- elsif app.is_a? URLMap
635
- app.instance_variable_get(:@mapping).each do |(host, path, appl)|
636
- next if !host.nil? && !options[:Host].nil? && options[:Host] != host
637
- path = '/'+path unless path[0] == ?/
638
- server.register(path, Rack::Handler::Mongrel.new(appl))
639
- end
640
- else
641
- raise ArgumentError, "first argument should be a Hash or URLMap"
642
- end
643
- else
644
- server.register('/', Rack::Handler::Mongrel.new(app))
655
+ ...
656
+ DEFAULT_OPTIONS = {
657
+ :Host => '0.0.0.0',
658
+ :Port => 8080,
659
+ :Threads => '0:16',
660
+ :Verbose => false
661
+ }
662
+
663
+ def self.run(app, options = {})
664
+ options = DEFAULT_OPTIONS.merge(options)
665
+
666
+ if options[:Verbose]
667
+ app = Rack::CommonLogger.new(app, STDOUT)
645
668
  end
669
+
670
+ if options[:environment]
671
+ ENV['RACK_ENV'] = options[:environment].to_s
672
+ end
673
+
674
+ server = ::Puma::Server.new(app)
675
+ min, max = options[:Threads].split(':', 2)
676
+
677
+ puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
678
+ puts "* Min threads: #{min}, max threads: #{max}"
679
+ puts "* Environment: #{ENV['RACK_ENV']}"
680
+ puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"
681
+
682
+ server.add_tcp_listener options[:Host], options[:Port]
683
+ server.min_threads = min
684
+ server.max_threads = max
646
685
  yield server if block_given?
647
- server.run.join
686
+
687
+ begin
688
+ server.run.join
689
+ rescue Interrupt
690
+ puts "* Gracefully stopping, waiting for requests to finish"
691
+ server.stop(true)
692
+ puts "* Goodbye!"
693
+ end
694
+
648
695
  end
649
696
  ```
650
697
 
@@ -1,5 +1,4 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1
+ <!DOCTYPE html>
3
2
 
4
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
4
  <head>
@@ -30,15 +29,11 @@
30
29
  More Ruby on Rails
31
30
  </span>
32
31
  <ul class="more-info-links s-hidden">
33
- <li class="more-info"><a href="http://rubyonrails.org/">Overview</a></li>
34
- <li class="more-info"><a href="http://rubyonrails.org/download">Download</a></li>
35
- <li class="more-info"><a href="http://rubyonrails.org/deploy">Deploy</a></li>
36
- <li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
37
- <li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
38
- <li class="more-info"><a href="http://rubyonrails.org/documentation">Documentation</a></li>
39
- <li class="more-info"><a href="http://rubyonrails.org/ecosystem">Ecosystem</a></li>
40
- <li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
41
32
  <li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
33
+ <li class="more-info"><a href="http://guides.rubyonrails.org/">Guides</a></li>
34
+ <li class="more-info"><a href="http://api.rubyonrails.org/">API</a></li>
35
+ <li class="more-info"><a href="http://stackoverflow.com/questions/tagged/ruby-on-rails">Ask for help</a></li>
36
+ <li class="more-info"><a href="https://github.com/rails/rails">Contribute on GitHub</a></li>
42
37
  </ul>
43
38
  </div>
44
39
  </div>
@@ -78,7 +73,6 @@
78
73
  </select>
79
74
  </li>
80
75
  </ul>
81
- </div>
82
76
  </div>
83
77
  </div>
84
78
  <hr class="hide" />
@@ -175,23 +175,22 @@ render template: "products/show"
175
175
 
176
176
  #### Rendering an Arbitrary File
177
177
 
178
- The `render` method can also use a view that's entirely outside of your application (perhaps you're sharing views between two Rails applications):
179
-
180
- ```ruby
181
- render "/u/apps/warehouse_app/current/app/views/products/show"
182
- ```
183
-
184
- Rails determines that this is a file render because of the leading slash character. To be explicit, you can use the `:file` option (which was required on Rails 2.2 and earlier):
178
+ The `render` method can also use a view that's entirely outside of your application:
185
179
 
186
180
  ```ruby
187
181
  render file: "/u/apps/warehouse_app/current/app/views/products/show"
188
182
  ```
189
183
 
190
- The `:file` option takes an absolute file-system path. Of course, you need to have rights to the view that you're using to render the content.
184
+ The `:file` option takes an absolute file-system path. Of course, you need to have rights
185
+ to the view that you're using to render the content.
186
+
187
+ NOTE: Using the `:file` option in combination with users input can lead to security problems
188
+ since an attacker could use this action to access security sensitive files in your file system.
191
189
 
192
- NOTE: By default, the file is rendered without using the current layout. If you want Rails to put the file into the current layout, you need to add the `layout: true` option.
190
+ NOTE: By default, the file is rendered using the current layout.
193
191
 
194
- TIP: If you're running Rails on Microsoft Windows, you should use the `:file` option to render a file, because Windows filenames do not have the same format as Unix filenames.
192
+ TIP: If you're running Rails on Microsoft Windows, you should use the `:file` option to
193
+ render a file, because Windows filenames do not have the same format as Unix filenames.
195
194
 
196
195
  #### Wrapping it up
197
196
 
@@ -248,7 +247,8 @@ service requests that are expecting something other than proper HTML.
248
247
 
249
248
  NOTE: By default, if you use the `:plain` option, the text is rendered without
250
249
  using the current layout. If you want Rails to put the text into the current
251
- layout, you need to add the `layout: true` option.
250
+ layout, you need to add the `layout: true` option and use the `.txt.erb`
251
+ extension for the layout file.
252
252
 
253
253
  #### Rendering HTML
254
254
 
@@ -263,7 +263,7 @@ TIP: This is useful when you're rendering a small snippet of HTML code.
263
263
  However, you might want to consider moving it to a template file if the markup
264
264
  is complex.
265
265
 
266
- NOTE: This option will escape HTML entities if the string is not html safe.
266
+ NOTE: This option will escape HTML entities if the string is not HTML safe.
267
267
 
268
268
  #### Rendering JSON
269
269
 
@@ -308,7 +308,7 @@ TIP: This option should be used only if you don't care about the content type of
308
308
  the response. Using `:plain` or `:html` might be more appropriate in most of the
309
309
  time.
310
310
 
311
- NOTE: Unless overriden, your response returned from this render option will be
311
+ NOTE: Unless overridden, your response returned from this render option will be
312
312
  `text/html`, as that is the default content type of Action Dispatch response.
313
313
 
314
314
  #### Options for `render`
@@ -506,33 +506,33 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
506
506
  end
507
507
  ```
508
508
 
509
- * `posts_controller.rb`
509
+ * `articles_controller.rb`
510
510
 
511
511
  ```ruby
512
- class PostsController < ApplicationController
512
+ class ArticlesController < ApplicationController
513
513
  end
514
514
  ```
515
515
 
516
- * `special_posts_controller.rb`
516
+ * `special_articles_controller.rb`
517
517
 
518
518
  ```ruby
519
- class SpecialPostsController < PostsController
519
+ class SpecialArticlesController < ArticlesController
520
520
  layout "special"
521
521
  end
522
522
  ```
523
523
 
524
- * `old_posts_controller.rb`
524
+ * `old_articles_controller.rb`
525
525
 
526
526
  ```ruby
527
- class OldPostsController < SpecialPostsController
527
+ class OldArticlesController < SpecialArticlesController
528
528
  layout false
529
529
 
530
530
  def show
531
- @post = Post.find(params[:id])
531
+ @article = Article.find(params[:id])
532
532
  end
533
533
 
534
534
  def index
535
- @old_posts = Post.older
535
+ @old_articles = Article.older
536
536
  render layout: "old"
537
537
  end
538
538
  # ...
@@ -542,10 +542,10 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
542
542
  In this application:
543
543
 
544
544
  * In general, views will be rendered in the `main` layout
545
- * `PostsController#index` will use the `main` layout
546
- * `SpecialPostsController#index` will use the `special` layout
547
- * `OldPostsController#show` will use no layout at all
548
- * `OldPostsController#index` will use the `old` layout
545
+ * `ArticlesController#index` will use the `main` layout
546
+ * `SpecialArticlesController#index` will use the `special` layout
547
+ * `OldArticlesController#show` will use no layout at all
548
+ * `OldArticlesController#index` will use the `old` layout
549
549
 
550
550
  #### Avoiding Double Render Errors
551
551
 
@@ -903,7 +903,7 @@ You can also specify multiple videos to play by passing an array of videos to th
903
903
  This will produce:
904
904
 
905
905
  ```erb
906
- <video><source src="trailer.ogg" /><source src="movie.ogg" /></video>
906
+ <video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
907
907
  ```
908
908
 
909
909
  #### Linking to Audio Files with the `audio_tag`
@@ -39,7 +39,10 @@ Only the latest release series will receive bug fixes. When enough bugs are
39
39
  fixed and its deemed worthy to release a new gem, this is the branch it happens
40
40
  from.
41
41
 
42
- **Currently included series:** `4.1.Z`, `4.0.Z`.
42
+ In special situations, where someone from the Core Team agrees to support more series,
43
+ they are included in the list of supported series.
44
+
45
+ **Currently included series:** `4.2.Z`, `4.1.Z` (Supported by Rafael França).
43
46
 
44
47
  Security Issues
45
48
  ---------------
@@ -54,7 +57,7 @@ be built from 1.2.2, and then added to the end of 1-2-stable. This means that
54
57
  security releases are easy to upgrade to if you're running the latest version
55
58
  of Rails.
56
59
 
57
- **Currently included series:** `4.1.Z`, `4.0.Z`.
60
+ **Currently included series:** `4.2.Z`, `4.1.Z`.
58
61
 
59
62
  Severe Security Issues
60
63
  ----------------------
@@ -63,7 +66,7 @@ For severe security issues we will provide new versions as above, and also the
63
66
  last major release series will receive patches and new versions. The
64
67
  classification of the security issue is judged by the core team.
65
68
 
66
- **Currently included series:** `4.1.Z`, `4.0.Z`, `3.2.Z`.
69
+ **Currently included series:** `4.2.Z`, `4.1.Z`, `3.2.Z`.
67
70
 
68
71
  Unsupported Release Series
69
72
  --------------------------
@@ -1,4 +1,4 @@
1
- Rails nested model forms
1
+ Rails Nested Model Forms
2
2
  ========================
3
3
 
4
4
  Creating a form for a model _and_ its associations can become quite tedious. Therefore Rails provides helpers to assist in dealing with the complexities of generating these forms _and_ the required CRUD operations to create, update, and destroy associations.
@@ -17,9 +17,9 @@ Model setup
17
17
 
18
18
  To be able to use the nested model functionality in your forms, the model will need to support some basic operations.
19
19
 
20
- First of all, it needs to define a writer method for the attribute that corresponds to the association you are building a nested model form for. The `fields_for` form helper will look for this method to decide whether or not a nested model form should be build.
20
+ First of all, it needs to define a writer method for the attribute that corresponds to the association you are building a nested model form for. The `fields_for` form helper will look for this method to decide whether or not a nested model form should be built.
21
21
 
22
- If the associated object is an array a form builder will be yielded for each object, else only a single form builder will be yielded.
22
+ If the associated object is an array, a form builder will be yielded for each object, else only a single form builder will be yielded.
23
23
 
24
24
  Consider a Person model with an associated Address. When asked to yield a nested FormBuilder for the `:address` attribute, the `fields_for` form helper will look for a method on the Person instance named `address_attributes=`.
25
25
 
@@ -54,6 +54,9 @@ class Person < ActiveRecord::Base
54
54
  end
55
55
  ```
56
56
 
57
+ NOTE: For greater detail on associations see [Active Record Associations](association_basics.html).
58
+ For a complete reference on associations please visit the API documentation for [ActiveRecord::Associations::ClassMethods](http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html).
59
+
57
60
  ### Custom model
58
61
 
59
62
  As you might have inflected from this explanation, you _don't_ necessarily need an ActiveRecord::Base model to use this functionality. The following examples are sufficient to enable the nested model form behavior:
@@ -220,6 +223,6 @@ As you can see it has generated 2 `project name` inputs, one for each new `proje
220
223
 
221
224
  You can basically see the `projects_attributes` hash as an array of attribute hashes, one for each model instance.
222
225
 
223
- NOTE: The reason that `fields_for` constructed a form which would result in a hash instead of an array is that it won't work for any forms nested deeper than one level deep.
226
+ NOTE: The reason that `fields_for` constructed a hash instead of an array is that it won't work for any form nested deeper than one level deep.
224
227
 
225
228
  TIP: You _can_ however pass an array to the writer method generated by `accepts_nested_attributes_for` if you're using plain Ruby or some other API access. See (TODO) for more info and example.