rails 4.1.4 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -10
- data/guides/CHANGELOG.md +15 -25
- data/guides/Rakefile +5 -3
- data/guides/assets/javascripts/guides.js +6 -0
- data/guides/assets/stylesheets/main.css +4 -1
- data/guides/bug_report_templates/action_controller_gem.rb +2 -2
- data/guides/bug_report_templates/action_controller_master.rb +3 -2
- data/guides/rails_guides/helpers.rb +1 -1
- data/guides/rails_guides/levenshtein.rb +29 -21
- data/guides/rails_guides/markdown/renderer.rb +1 -1
- data/guides/rails_guides/markdown.rb +11 -7
- data/guides/rails_guides.rb +2 -2
- data/guides/source/2_2_release_notes.md +1 -1
- data/guides/source/2_3_release_notes.md +4 -4
- data/guides/source/3_0_release_notes.md +8 -8
- data/guides/source/3_1_release_notes.md +5 -2
- data/guides/source/3_2_release_notes.md +6 -3
- data/guides/source/4_0_release_notes.md +6 -3
- data/guides/source/4_1_release_notes.md +10 -11
- data/guides/source/4_2_release_notes.md +850 -0
- data/guides/source/_license.html.erb +1 -1
- data/guides/source/_welcome.html.erb +2 -8
- data/guides/source/action_controller_overview.md +84 -10
- data/guides/source/action_mailer_basics.md +91 -28
- data/guides/source/action_view_overview.md +140 -130
- data/guides/source/active_job_basics.md +318 -0
- data/guides/source/active_model_basics.md +371 -17
- data/guides/source/active_record_basics.md +19 -18
- data/guides/source/active_record_callbacks.md +12 -9
- data/guides/source/{migrations.md → active_record_migrations.md} +135 -226
- data/guides/source/active_record_postgresql.md +433 -0
- data/guides/source/active_record_querying.md +269 -259
- data/guides/source/active_record_validations.md +21 -12
- data/guides/source/active_support_core_extensions.md +113 -73
- data/guides/source/active_support_instrumentation.md +10 -7
- data/guides/source/api_documentation_guidelines.md +62 -16
- data/guides/source/asset_pipeline.md +264 -67
- data/guides/source/association_basics.md +81 -74
- data/guides/source/caching_with_rails.md +32 -7
- data/guides/source/command_line.md +52 -30
- data/guides/source/configuring.md +132 -29
- data/guides/source/constant_autoloading_and_reloading.md +1297 -0
- data/guides/source/contributing_to_ruby_on_rails.md +192 -112
- data/guides/source/credits.html.erb +2 -2
- data/guides/source/debugging_rails_applications.md +448 -294
- data/guides/source/development_dependencies_install.md +47 -36
- data/guides/source/documents.yaml +19 -7
- data/guides/source/engines.md +210 -189
- data/guides/source/form_helpers.md +79 -56
- data/guides/source/generators.md +24 -11
- data/guides/source/getting_started.md +339 -201
- data/guides/source/i18n.md +111 -68
- data/guides/source/index.html.erb +1 -0
- data/guides/source/initialization.md +109 -62
- data/guides/source/layout.html.erb +1 -4
- data/guides/source/layouts_and_rendering.md +18 -17
- data/guides/source/maintenance_policy.md +26 -4
- data/guides/source/nested_model_forms.md +7 -4
- data/guides/source/plugins.md +27 -27
- data/guides/source/rails_application_templates.md +21 -3
- data/guides/source/rails_on_rack.md +12 -9
- data/guides/source/routing.md +100 -74
- data/guides/source/ruby_on_rails_guides_guidelines.md +11 -12
- data/guides/source/security.md +40 -34
- data/guides/source/testing.md +188 -117
- data/guides/source/upgrading_ruby_on_rails.md +284 -29
- data/guides/source/working_with_javascript_in_rails.md +18 -16
- data/guides/w3c_validator.rb +2 -0
- metadata +40 -94
- data/guides/code/getting_started/Gemfile +0 -40
- data/guides/code/getting_started/Gemfile.lock +0 -125
- data/guides/code/getting_started/README.rdoc +0 -28
- data/guides/code/getting_started/Rakefile +0 -6
- data/guides/code/getting_started/app/assets/javascripts/application.js +0 -15
- data/guides/code/getting_started/app/assets/javascripts/comments.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/posts.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/javascripts/welcome.js.coffee +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/application.css +0 -13
- data/guides/code/getting_started/app/assets/stylesheets/comments.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/posts.css.scss +0 -3
- data/guides/code/getting_started/app/assets/stylesheets/welcome.css.scss +0 -3
- data/guides/code/getting_started/app/controllers/application_controller.rb +0 -5
- data/guides/code/getting_started/app/controllers/comments_controller.rb +0 -23
- data/guides/code/getting_started/app/controllers/posts_controller.rb +0 -53
- data/guides/code/getting_started/app/controllers/welcome_controller.rb +0 -4
- data/guides/code/getting_started/app/helpers/application_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/comments_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/posts_helper.rb +0 -2
- data/guides/code/getting_started/app/helpers/welcome_helper.rb +0 -2
- data/guides/code/getting_started/app/models/comment.rb +0 -3
- data/guides/code/getting_started/app/models/post.rb +0 -7
- data/guides/code/getting_started/app/views/comments/_comment.html.erb +0 -15
- data/guides/code/getting_started/app/views/comments/_form.html.erb +0 -13
- data/guides/code/getting_started/app/views/layouts/application.html.erb +0 -14
- data/guides/code/getting_started/app/views/posts/_form.html.erb +0 -27
- data/guides/code/getting_started/app/views/posts/edit.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/index.html.erb +0 -21
- data/guides/code/getting_started/app/views/posts/new.html.erb +0 -5
- data/guides/code/getting_started/app/views/posts/show.html.erb +0 -18
- data/guides/code/getting_started/app/views/welcome/index.html.erb +0 -4
- data/guides/code/getting_started/bin/bundle +0 -4
- data/guides/code/getting_started/bin/rails +0 -4
- data/guides/code/getting_started/bin/rake +0 -4
- data/guides/code/getting_started/config/application.rb +0 -18
- data/guides/code/getting_started/config/boot.rb +0 -4
- data/guides/code/getting_started/config/database.yml +0 -25
- data/guides/code/getting_started/config/environment.rb +0 -5
- data/guides/code/getting_started/config/environments/development.rb +0 -30
- data/guides/code/getting_started/config/environments/production.rb +0 -80
- data/guides/code/getting_started/config/environments/test.rb +0 -36
- data/guides/code/getting_started/config/initializers/backtrace_silencers.rb +0 -7
- data/guides/code/getting_started/config/initializers/filter_parameter_logging.rb +0 -4
- data/guides/code/getting_started/config/initializers/inflections.rb +0 -16
- data/guides/code/getting_started/config/initializers/locale.rb +0 -9
- data/guides/code/getting_started/config/initializers/mime_types.rb +0 -5
- data/guides/code/getting_started/config/initializers/secret_token.rb +0 -12
- data/guides/code/getting_started/config/initializers/session_store.rb +0 -3
- data/guides/code/getting_started/config/initializers/wrap_parameters.rb +0 -14
- data/guides/code/getting_started/config/locales/en.yml +0 -23
- data/guides/code/getting_started/config/routes.rb +0 -7
- data/guides/code/getting_started/config.ru +0 -4
- data/guides/code/getting_started/db/migrate/20130122042648_create_posts.rb +0 -10
- data/guides/code/getting_started/db/migrate/20130122045842_create_comments.rb +0 -11
- data/guides/code/getting_started/db/schema.rb +0 -33
- data/guides/code/getting_started/db/seeds.rb +0 -7
- data/guides/code/getting_started/public/404.html +0 -60
- data/guides/code/getting_started/public/422.html +0 -60
- data/guides/code/getting_started/public/500.html +0 -59
- data/guides/code/getting_started/public/favicon.ico +0 -0
- data/guides/code/getting_started/public/robots.txt +0 -5
- data/guides/code/getting_started/test/controllers/comments_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/posts_controller_test.rb +0 -7
- data/guides/code/getting_started/test/controllers/welcome_controller_test.rb +0 -9
- data/guides/code/getting_started/test/fixtures/comments.yml +0 -11
- data/guides/code/getting_started/test/fixtures/posts.yml +0 -9
- data/guides/code/getting_started/test/helpers/comments_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/posts_helper_test.rb +0 -4
- data/guides/code/getting_started/test/helpers/welcome_helper_test.rb +0 -4
- data/guides/code/getting_started/test/models/comment_test.rb +0 -7
- data/guides/code/getting_started/test/models/post_test.rb +0 -7
- 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
|
|
121
|
+
* sqlite3
|
|
123
122
|
* thor
|
|
124
|
-
* treetop
|
|
125
123
|
* tzinfo
|
|
126
124
|
|
|
127
125
|
### `rails/commands.rb`
|
|
@@ -166,6 +164,7 @@ is called.
|
|
|
166
164
|
COMMAND_WHITELIST = %(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!
|
|
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
|
|
289
|
-
pid
|
|
290
|
-
Port
|
|
291
|
-
Host
|
|
292
|
-
AccessLog
|
|
293
|
-
config
|
|
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 ||=
|
|
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
|
-
|
|
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 =
|
|
463
|
-
|
|
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
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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"
|
|
@@ -526,8 +556,8 @@ The rest of `config/application.rb` defines the configuration for the
|
|
|
526
556
|
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
|
-
`Blog`, here we would find `
|
|
530
|
-
defined in `rails/application.rb
|
|
559
|
+
`Blog`, here we would find `Rails.application.initialize!`, which is
|
|
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 ||=
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
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
|
|
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>
|
|
@@ -36,7 +35,6 @@
|
|
|
36
35
|
<li class="more-info"><a href="https://github.com/rails/rails">Code</a></li>
|
|
37
36
|
<li class="more-info"><a href="http://rubyonrails.org/screencasts">Screencasts</a></li>
|
|
38
37
|
<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
38
|
<li class="more-info"><a href="http://rubyonrails.org/community">Community</a></li>
|
|
41
39
|
<li class="more-info"><a href="http://weblog.rubyonrails.org/">Blog</a></li>
|
|
42
40
|
</ul>
|
|
@@ -78,7 +76,6 @@
|
|
|
78
76
|
</select>
|
|
79
77
|
</li>
|
|
80
78
|
</ul>
|
|
81
|
-
</div>
|
|
82
79
|
</div>
|
|
83
80
|
</div>
|
|
84
81
|
<hr class="hide" />
|
|
@@ -189,7 +189,7 @@ render file: "/u/apps/warehouse_app/current/app/views/products/show"
|
|
|
189
189
|
|
|
190
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.
|
|
191
191
|
|
|
192
|
-
NOTE: By default, the file is rendered
|
|
192
|
+
NOTE: By default, the file is rendered using the current layout.
|
|
193
193
|
|
|
194
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.
|
|
195
195
|
|
|
@@ -248,7 +248,8 @@ service requests that are expecting something other than proper HTML.
|
|
|
248
248
|
|
|
249
249
|
NOTE: By default, if you use the `:plain` option, the text is rendered without
|
|
250
250
|
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.
|
|
251
|
+
layout, you need to add the `layout: true` option and use the `.txt.erb`
|
|
252
|
+
extension for the layout file.
|
|
252
253
|
|
|
253
254
|
#### Rendering HTML
|
|
254
255
|
|
|
@@ -263,7 +264,7 @@ TIP: This is useful when you're rendering a small snippet of HTML code.
|
|
|
263
264
|
However, you might want to consider moving it to a template file if the markup
|
|
264
265
|
is complex.
|
|
265
266
|
|
|
266
|
-
NOTE: This option will escape HTML entities if the string is not
|
|
267
|
+
NOTE: This option will escape HTML entities if the string is not HTML safe.
|
|
267
268
|
|
|
268
269
|
#### Rendering JSON
|
|
269
270
|
|
|
@@ -308,7 +309,7 @@ TIP: This option should be used only if you don't care about the content type of
|
|
|
308
309
|
the response. Using `:plain` or `:html` might be more appropriate in most of the
|
|
309
310
|
time.
|
|
310
311
|
|
|
311
|
-
NOTE: Unless
|
|
312
|
+
NOTE: Unless overridden, your response returned from this render option will be
|
|
312
313
|
`text/html`, as that is the default content type of Action Dispatch response.
|
|
313
314
|
|
|
314
315
|
#### Options for `render`
|
|
@@ -506,33 +507,33 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
|
|
|
506
507
|
end
|
|
507
508
|
```
|
|
508
509
|
|
|
509
|
-
* `
|
|
510
|
+
* `articles_controller.rb`
|
|
510
511
|
|
|
511
512
|
```ruby
|
|
512
|
-
class
|
|
513
|
+
class ArticlesController < ApplicationController
|
|
513
514
|
end
|
|
514
515
|
```
|
|
515
516
|
|
|
516
|
-
* `
|
|
517
|
+
* `special_articles_controller.rb`
|
|
517
518
|
|
|
518
519
|
```ruby
|
|
519
|
-
class
|
|
520
|
+
class SpecialArticlesController < ArticlesController
|
|
520
521
|
layout "special"
|
|
521
522
|
end
|
|
522
523
|
```
|
|
523
524
|
|
|
524
|
-
* `
|
|
525
|
+
* `old_articles_controller.rb`
|
|
525
526
|
|
|
526
527
|
```ruby
|
|
527
|
-
class
|
|
528
|
+
class OldArticlesController < SpecialArticlesController
|
|
528
529
|
layout false
|
|
529
530
|
|
|
530
531
|
def show
|
|
531
|
-
@
|
|
532
|
+
@article = Article.find(params[:id])
|
|
532
533
|
end
|
|
533
534
|
|
|
534
535
|
def index
|
|
535
|
-
@
|
|
536
|
+
@old_articles = Article.older
|
|
536
537
|
render layout: "old"
|
|
537
538
|
end
|
|
538
539
|
# ...
|
|
@@ -542,10 +543,10 @@ Layout declarations cascade downward in the hierarchy, and more specific layout
|
|
|
542
543
|
In this application:
|
|
543
544
|
|
|
544
545
|
* In general, views will be rendered in the `main` layout
|
|
545
|
-
* `
|
|
546
|
-
* `
|
|
547
|
-
* `
|
|
548
|
-
* `
|
|
546
|
+
* `ArticlesController#index` will use the `main` layout
|
|
547
|
+
* `SpecialArticlesController#index` will use the `special` layout
|
|
548
|
+
* `OldArticlesController#show` will use no layout at all
|
|
549
|
+
* `OldArticlesController#index` will use the `old` layout
|
|
549
550
|
|
|
550
551
|
#### Avoiding Double Render Errors
|
|
551
552
|
|
|
@@ -903,7 +904,7 @@ You can also specify multiple videos to play by passing an array of videos to th
|
|
|
903
904
|
This will produce:
|
|
904
905
|
|
|
905
906
|
```erb
|
|
906
|
-
<video><source src="trailer.ogg" /><source src="
|
|
907
|
+
<video><source src="/videos/trailer.ogg" /><source src="/videos/trailer.flv" /></video>
|
|
907
908
|
```
|
|
908
909
|
|
|
909
910
|
#### Linking to Audio Files with the `audio_tag`
|
|
@@ -3,10 +3,29 @@ Maintenance Policy for Ruby on Rails
|
|
|
3
3
|
|
|
4
4
|
Support of the Rails framework is divided into four groups: New features, bug
|
|
5
5
|
fixes, security issues, and severe security issues. They are handled as
|
|
6
|
-
follows, all versions in
|
|
6
|
+
follows, all versions in `X.Y.Z` format.
|
|
7
7
|
|
|
8
8
|
--------------------------------------------------------------------------------
|
|
9
9
|
|
|
10
|
+
Rails follows a shifted version of [semver](http://semver.org/):
|
|
11
|
+
|
|
12
|
+
**Patch `Z`**
|
|
13
|
+
|
|
14
|
+
Only bug fixes, no API changes, no new features.
|
|
15
|
+
Except as necessary for security fixes.
|
|
16
|
+
|
|
17
|
+
**Minor `Y`**
|
|
18
|
+
|
|
19
|
+
New features, may contain API changes (Serve as major versions of Semver).
|
|
20
|
+
Breaking changes are paired with deprecation notices in the previous minor
|
|
21
|
+
or major release.
|
|
22
|
+
|
|
23
|
+
**Major `X`**
|
|
24
|
+
|
|
25
|
+
New features, will likely contain API changes. The difference between Rails'
|
|
26
|
+
minor and major releases is the magnitude of breaking changes, and usually
|
|
27
|
+
reserved for special occasions.
|
|
28
|
+
|
|
10
29
|
New Features
|
|
11
30
|
------------
|
|
12
31
|
|
|
@@ -20,7 +39,10 @@ Only the latest release series will receive bug fixes. When enough bugs are
|
|
|
20
39
|
fixed and its deemed worthy to release a new gem, this is the branch it happens
|
|
21
40
|
from.
|
|
22
41
|
|
|
23
|
-
|
|
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).
|
|
24
46
|
|
|
25
47
|
Security Issues
|
|
26
48
|
---------------
|
|
@@ -35,7 +57,7 @@ be built from 1.2.2, and then added to the end of 1-2-stable. This means that
|
|
|
35
57
|
security releases are easy to upgrade to if you're running the latest version
|
|
36
58
|
of Rails.
|
|
37
59
|
|
|
38
|
-
**Currently included series:** 4.
|
|
60
|
+
**Currently included series:** `4.2.Z`, `4.1.Z`.
|
|
39
61
|
|
|
40
62
|
Severe Security Issues
|
|
41
63
|
----------------------
|
|
@@ -44,7 +66,7 @@ For severe security issues we will provide new versions as above, and also the
|
|
|
44
66
|
last major release series will receive patches and new versions. The
|
|
45
67
|
classification of the security issue is judged by the core team.
|
|
46
68
|
|
|
47
|
-
**Currently included series:** 4.
|
|
69
|
+
**Currently included series:** `4.2.Z`, `4.1.Z`, `3.2.Z`.
|
|
48
70
|
|
|
49
71
|
Unsupported Release Series
|
|
50
72
|
--------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Rails
|
|
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
|
|
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
|
|
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.
|