aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/actionmailer.gemspec1
-rw-r--r--actionpack/actionpack.gemspec1
-rw-r--r--actionpack/lib/abstract_controller/base.rb16
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb2
-rw-r--r--activemodel/activemodel.gemspec1
-rw-r--r--activerecord/activerecord.gemspec1
-rw-r--r--activerecord/lib/active_record/aggregations.rb6
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb489
-rw-r--r--activerecord/lib/active_record/associations/preloader.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb21
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb4
-rw-r--r--activerecord/test/cases/connection_pool_test.rb4
-rw-r--r--activerecord/test/cases/pooled_connections_test.rb4
-rw-r--r--activerecord/test/cases/reaper_test.rb2
-rw-r--r--activesupport/activesupport.gemspec1
-rw-r--r--guides/assets/images/belongs_to.pngbin34017 -> 26076 bytes
-rw-r--r--guides/assets/images/book_icon.gifbin337 -> 329 bytes
-rw-r--r--guides/assets/images/challenge.pngbin54134 -> 33373 bytes
-rw-r--r--guides/assets/images/chapters_icon.gifbin628 -> 620 bytes
-rw-r--r--guides/assets/images/check_bullet.gifbin384 -> 376 bytes
-rw-r--r--guides/assets/images/credits_pic_blank.gifbin613 -> 597 bytes
-rw-r--r--guides/assets/images/csrf.pngbin41996 -> 32179 bytes
-rw-r--r--guides/assets/images/customized_error_messages.pngbin5055 -> 2561 bytes
-rw-r--r--guides/assets/images/edge_badge.pngbin7945 -> 5964 bytes
-rw-r--r--guides/assets/images/error_messages.pngbin14645 -> 10964 bytes
-rw-r--r--guides/assets/images/getting_started/confirm_dialog.pngbin36070 -> 29542 bytes
-rw-r--r--guides/assets/images/getting_started/form_with_errors.pngbin20820 -> 14031 bytes
-rw-r--r--guides/assets/images/getting_started/index_action_with_edit_link.pngbin15547 -> 9772 bytes
-rw-r--r--guides/assets/images/getting_started/new_post.pngbin14334 -> 5888 bytes
-rw-r--r--guides/assets/images/getting_started/post_with_comments.pngbin31630 -> 18496 bytes
-rw-r--r--guides/assets/images/getting_started/routing_error_no_controller.pngbin15744 -> 6268 bytes
-rw-r--r--guides/assets/images/getting_started/routing_error_no_route_matches.pngbin16065 -> 6508 bytes
-rw-r--r--guides/assets/images/getting_started/show_action_for_posts.pngbin6885 -> 2991 bytes
-rw-r--r--guides/assets/images/getting_started/template_is_missing_posts_new.pngbin15168 -> 5851 bytes
-rw-r--r--guides/assets/images/getting_started/undefined_method_post_path.pngbin15254 -> 9217 bytes
-rw-r--r--guides/assets/images/getting_started/unknown_action_create_for_posts.pngbin12652 -> 4146 bytes
-rw-r--r--guides/assets/images/getting_started/unknown_action_new_for_posts.pngbin12756 -> 4208 bytes
-rw-r--r--guides/assets/images/grey_bullet.gifbin45 -> 37 bytes
-rw-r--r--guides/assets/images/habtm.pngbin63801 -> 49332 bytes
-rw-r--r--guides/assets/images/has_many.pngbin38582 -> 28988 bytes
-rw-r--r--guides/assets/images/has_many_through.pngbin100220 -> 79428 bytes
-rw-r--r--guides/assets/images/has_one.pngbin39022 -> 29072 bytes
-rw-r--r--guides/assets/images/has_one_through.pngbin92594 -> 72434 bytes
-rw-r--r--guides/assets/images/header_backdrop.pngbin882 -> 224 bytes
-rw-r--r--guides/assets/images/i18n/demo_html_safe.pngbin11946 -> 10073 bytes
-rw-r--r--guides/assets/images/i18n/demo_localized_pirate.pngbin15027 -> 11485 bytes
-rw-r--r--guides/assets/images/i18n/demo_translated_en.pngbin12057 -> 9325 bytes
-rw-r--r--guides/assets/images/i18n/demo_translated_pirate.pngbin13392 -> 10202 bytes
-rw-r--r--guides/assets/images/i18n/demo_translation_missing.pngbin13143 -> 10260 bytes
-rw-r--r--guides/assets/images/i18n/demo_untranslated.pngbin11925 -> 9224 bytes
-rw-r--r--guides/assets/images/icons/callouts/1.pngbin329 -> 147 bytes
-rw-r--r--guides/assets/images/icons/callouts/10.pngbin361 -> 183 bytes
-rw-r--r--guides/assets/images/icons/callouts/11.pngbin565 -> 290 bytes
-rw-r--r--guides/assets/images/icons/callouts/12.pngbin617 -> 322 bytes
-rw-r--r--guides/assets/images/icons/callouts/13.pngbin623 -> 328 bytes
-rw-r--r--guides/assets/images/icons/callouts/14.pngbin411 -> 246 bytes
-rw-r--r--guides/assets/images/icons/callouts/15.pngbin640 -> 340 bytes
-rw-r--r--guides/assets/images/icons/callouts/2.pngbin353 -> 168 bytes
-rw-r--r--guides/assets/images/icons/callouts/3.pngbin350 -> 170 bytes
-rw-r--r--guides/assets/images/icons/callouts/4.pngbin345 -> 165 bytes
-rw-r--r--guides/assets/images/icons/callouts/5.pngbin348 -> 169 bytes
-rw-r--r--guides/assets/images/icons/callouts/6.pngbin355 -> 176 bytes
-rw-r--r--guides/assets/images/icons/callouts/7.pngbin344 -> 160 bytes
-rw-r--r--guides/assets/images/icons/callouts/8.pngbin357 -> 176 bytes
-rw-r--r--guides/assets/images/icons/callouts/9.pngbin357 -> 177 bytes
-rw-r--r--guides/assets/images/icons/caution.pngbin2554 -> 2300 bytes
-rw-r--r--guides/assets/images/icons/example.pngbin2354 -> 2079 bytes
-rw-r--r--guides/assets/images/icons/home.pngbin1340 -> 1163 bytes
-rw-r--r--guides/assets/images/icons/important.pngbin2657 -> 2451 bytes
-rw-r--r--guides/assets/images/icons/next.pngbin1302 -> 1146 bytes
-rw-r--r--guides/assets/images/icons/note.pngbin2730 -> 2155 bytes
-rw-r--r--guides/assets/images/icons/prev.pngbin1348 -> 1126 bytes
-rw-r--r--guides/assets/images/icons/tip.pngbin2602 -> 2248 bytes
-rw-r--r--guides/assets/images/icons/up.pngbin1320 -> 1133 bytes
-rw-r--r--guides/assets/images/icons/warning.pngbin2828 -> 2616 bytes
-rw-r--r--guides/assets/images/nav_arrow.gifbin427 -> 419 bytes
-rw-r--r--guides/assets/images/oscardelben.jpgbin0 -> 6299 bytes
-rw-r--r--guides/assets/images/polymorphic.pngbin85248 -> 66415 bytes
-rw-r--r--guides/assets/images/rails_guides_logo.gifbin5114 -> 5106 bytes
-rw-r--r--guides/assets/images/rails_welcome.pngbin121314 -> 71979 bytes
-rw-r--r--guides/assets/images/session_fixation.pngbin47860 -> 38451 bytes
-rw-r--r--guides/assets/images/tab_grey.gifbin4924 -> 4684 bytes
-rw-r--r--guides/assets/images/tab_info.gifbin4762 -> 4522 bytes
-rw-r--r--guides/assets/images/tab_note.gifbin4807 -> 4566 bytes
-rw-r--r--guides/assets/images/tab_red.gifbin4753 -> 4507 bytes
-rw-r--r--guides/assets/images/tab_yellow.gifbin4759 -> 4519 bytes
-rw-r--r--guides/assets/images/tab_yellow.pngbin1611 -> 1441 bytes
-rw-r--r--guides/assets/images/validation_error_messages.pngbin1107 -> 583 bytes
-rw-r--r--guides/source/configuring.textile2
-rw-r--r--guides/source/credits.html.erb4
-rw-r--r--guides/source/debugging_rails_applications.textile2
-rw-r--r--guides/source/getting_started.textile2
-rw-r--r--guides/source/initialization.textile108
-rw-r--r--rails.gemspec1
-rw-r--r--railties/lib/rails/generators/actions.rb3
-rw-r--r--railties/railties.gemspec1
96 files changed, 587 insertions, 91 deletions
diff --git a/actionmailer/actionmailer.gemspec b/actionmailer/actionmailer.gemspec
index 90503edc20..0c669e2e91 100644
--- a/actionmailer/actionmailer.gemspec
+++ b/actionmailer/actionmailer.gemspec
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
s.summary = 'Email composition, delivery, and receiving framework (part of Rails).'
s.description = 'Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 589a67dc02..ae26d6f9e5 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
s.summary = 'Web-flow and rendering framework putting the VC in MVC (part of Rails).'
s.description = 'Web apps on Rails. Simple, battle-tested conventions for building and testing MVC web applications. Works with any Rack-compatible server.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb
index 97a9eec144..9c3960961b 100644
--- a/actionpack/lib/abstract_controller/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -51,7 +51,7 @@ module AbstractController
# to specify particular actions as hidden.
#
# ==== Returns
- # * <tt>array</tt> - An array of method names that should not be considered actions.
+ # * <tt>Array</tt> - An array of method names that should not be considered actions.
def hidden_actions
[]
end
@@ -63,7 +63,7 @@ module AbstractController
# itself. Finally, #hidden_actions are removed.
#
# ==== Returns
- # * <tt>set</tt> - A set of all methods that should be considered actions.
+ # * <tt>Set</tt> - A set of all methods that should be considered actions.
def action_methods
@action_methods ||= begin
# All public instance methods of this class, including ancestors
@@ -92,11 +92,12 @@ module AbstractController
# controller_path.
#
# ==== Returns
- # * <tt>string</tt>
+ # * <tt>String</tt>
def controller_path
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
end
+ # Refresh the cached action_methods when a new action_method is added.
def method_added(name)
super
clear_action_methods!
@@ -130,6 +131,7 @@ module AbstractController
self.class.controller_path
end
+ # Delegates to the class' #action_methods
def action_methods
self.class.action_methods
end
@@ -139,8 +141,14 @@ module AbstractController
#
# Notice that <tt>action_methods.include?("foo")</tt> may return
# false and <tt>available_action?("foo")</tt> returns true because
- # available action consider actions that are also available
+ # this method considers actions that are also available
# through other means, for example, implicit render ones.
+ #
+ # ==== Parameters
+ # * <tt>action_name</tt> - The name of an action to be tested
+ #
+ # ==== Returns
+ # * <tt>TrueClass</tt>, <tt>FalseClass</tt>
def available_action?(action_name)
method_for_action(action_name).present?
end
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index ad8885b708..ac150882b1 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -342,7 +342,7 @@ module ActionView
# Example:
#
# <%= form_for(@post) do |f| %>
- # <% f.fields_for(:comments, :include_id => false) do |cf| %>
+ # <%= f.fields_for(:comments, :include_id => false) do |cf| %>
# ...
# <% end %>
# <% end %>
diff --git a/activemodel/activemodel.gemspec b/activemodel/activemodel.gemspec
index f2d004fb0a..66f324a1a1 100644
--- a/activemodel/activemodel.gemspec
+++ b/activemodel/activemodel.gemspec
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
s.description = 'A toolkit for building modeling frameworks like Active Record. Rich support for attributes, callbacks, validations, observers, serialization, internationalization, and testing.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec
index e8e5f4adfe..dca7f13fd2 100644
--- a/activerecord/activerecord.gemspec
+++ b/activerecord/activerecord.gemspec
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
s.description = 'Databases on Rails. Build a persistent domain model by mapping database tables to Ruby classes. Strong conventions for associations, validations, aggregations, migrations, and testing come baked-in.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index f0b549e5ad..3ae7030caa 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -10,9 +10,9 @@ module ActiveRecord
# Active Record implements aggregation through a macro-like class method called +composed_of+
# for representing attributes as value objects. It expresses relationships like "Account [is]
# composed of Money [among other things]" or "Person [is] composed of [an] address". Each call
- # to the macro adds a description of how the value objects are created from the attributes of
- # the entity object (when the entity is initialized either as a new object or from finding an
- # existing object) and how it can be turned back into attributes (when the entity is saved to
+ # to the macro adds a description of how the value objects are created from the attributes of
+ # the entity object (when the entity is initialized either as a new object or from finding an
+ # existing object) and how it can be turned back into attributes (when the entity is saved to
# the database).
#
# class Customer < ActiveRecord::Base
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index fa316a8c9d..100fb38dec 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -37,9 +37,107 @@ module ActiveRecord
delegate :target, :load_target, :loaded?, :to => :@association
##
+ # :method: select
+ #
+ # :call-seq:
+ # select(select = nil)
+ # select(&block)
+ #
+ # Works in two ways.
+ #
+ # *First:* Specify a subset of fields to be selected from the result set.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.select(:name)
+ # # => [
+ # # #<Pet id: nil, name: "Fancy-Fancy">,
+ # # #<Pet id: nil, name: "Spook">,
+ # # #<Pet id: nil, name: "Choo-Choo">
+ # # ]
+ #
+ # person.pets.select([:id, :name])
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy">,
+ # # #<Pet id: 2, name: "Spook">,
+ # # #<Pet id: 3, name: "Choo-Choo">
+ # # ]
+ #
+ # Be careful because this also means you’re initializing a model
+ # object with only the fields that you’ve selected. If you attempt
+ # to access a field that is not in the initialized record you’ll
+ # receive:
+ #
+ # person.pets.select(:name).first.person_id
+ # # => ActiveModel::MissingAttributeError: missing attribute: person_id
+ #
+ # *Second:* You can pass a block so it can be used just like Array#select.
+ # This build an array of objects from the database for the scope,
+ # converting them into an array and iterating through them using
+ # Array#select.
+ #
+ # person.pets.select { |pet| pet.name =~ /oo/ }
+ # # => [
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.select(:name) { |pet| pet.name =~ /oo/ }
+ # # => [
+ # # #<Pet id: 2, name: "Spook">,
+ # # #<Pet id: 3, name: "Choo-Choo">
+ # # ]
+
+ ##
+ # :method: find
+ #
+ # :call-seq:
+ # find(*args, &block)
+ #
+ # Finds an object in the collection responding to the +id+. Uses the same
+ # rules as +ActiveRecord::Base.find+. Returns +ActiveRecord::RecordNotFound++
+ # error if the object can not be found.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.find(1) # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
+ # person.pets.find(4) # => ActiveRecord::RecordNotFound: Couldn't find Pet with id=4
+ #
+ # person.pets.find(2) { |pet| pet.name.downcase! }
+ # # => #<Pet id: 2, name: "fancy-fancy", person_id: 1>
+ #
+ # person.pets.find(2, 3)
+ # # => [
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+
+ ##
# :method: first
+ #
+ # :call-seq:
+ # first(limit = nil)
+ #
# Returns the first record, or the first +n+ records, from the collection.
- # If the collection is empty, the first form returns nil, and the second
+ # If the collection is empty, the first form returns +nil+, and the second
# form returns an empty array.
#
# class Person < ActiveRecord::Base
@@ -67,8 +165,12 @@ module ActiveRecord
##
# :method: last
+ #
+ # :call-seq:
+ # last(limit = nil)
+ #
# Returns the last record, or the last +n+ records, from the collection.
- # If the collection is empty, the first form returns nil, and the second
+ # If the collection is empty, the first form returns +nil+, and the second
# form returns an empty array.
#
# class Person < ActiveRecord::Base
@@ -95,7 +197,95 @@ module ActiveRecord
# another_person_without.pets.last(3) # => []
##
+ # :method: build
+ #
+ # :call-seq:
+ # build(attributes = {}, options = {}, &block)
+ #
+ # Returns a new object of the collection type that has been instantiated
+ # with +attributes+ and linked to this object, but have not yet been saved.
+ # You can pass an array of attributes hashes, this will return an array
+ # with the new objects.
+ #
+ # class Person
+ # has_many :pets
+ # end
+ #
+ # person.pets.build
+ # # => #<Pet id: nil, name: nil, person_id: 1>
+ #
+ # person.pets.build(name: 'Fancy-Fancy')
+ # # => #<Pet id: nil, name: "Fancy-Fancy", person_id: 1>
+ #
+ # person.pets.build([{name: 'Spook'}, {name: 'Choo-Choo'}, {name: 'Brain'}])
+ # # => [
+ # # #<Pet id: nil, name: "Spook", person_id: 1>,
+ # # #<Pet id: nil, name: "Choo-Choo", person_id: 1>,
+ # # #<Pet id: nil, name: "Brain", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 5 # size of the collection
+ # person.pets.count # => 0 # count from database
+
+ ##
+ # :method: create
+ #
+ # :call-seq:
+ # create(attributes = {}, options = {}, &block)
+ #
+ # Returns a new object of the collection type that has been instantiated with
+ # attributes, linked to this object and that has already been saved (if it
+ # passes the validations).
+ #
+ # class Person
+ # has_many :pets
+ # end
+ #
+ # person.pets.create(name: 'Fancy-Fancy')
+ # # => #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>
+ #
+ # person.pets.create([{name: 'Spook'}, {name: 'Choo-Choo'}])
+ # # => [
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 3
+ # person.pets.count # => 3
+ #
+ # person.pets.find(1, 2, 3)
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+
+ ##
+ # :method: create!
+ #
+ # :call-seq:
+ # create!(attributes = {}, options = {}, &block)
+ #
+ # Like +create+, except that if the record is invalid, raises an exception.
+ #
+ # class Person
+ # has_many :pets
+ # end
+ #
+ # class Pet
+ # attr_accessible :name
+ # validates :name, presence: true
+ # end
+ #
+ # person.pets.create!(name: nil)
+ # # => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
+
+ ##
# :method: concat
+ #
+ # :call-seq:
+ # concat(*records)
+ #
# Add one or more records to the collection by setting their foreign keys
# to the association's primary key. Since << flattens its argument list and
# inserts each record, +push+ and +concat+ behave identically. Returns +self+
@@ -123,6 +313,10 @@ module ActiveRecord
##
# :method: replace
+ #
+ # :call-seq:
+ # replace(other_array)
+ #
# Replace this collection with +other_array+. This will perform a diff
# and delete/add only records that have changed.
#
@@ -147,23 +341,249 @@ module ActiveRecord
# # => ActiveRecord::AssociationTypeMismatch: Pet expected, got String
##
+ # :method: delete_all
+ #
+ # Deletes all the records from the collection. For +has_many+ asssociations,
+ # the deletion is done according to the strategy specified by the <tt>:dependent</tt>
+ # option. Returns an array with the deleted records.
+ #
+ # If no <tt>:dependent</tt> option is given, then it will follow the
+ # default strategy. The default strategy is <tt>:nullify</tt>. This
+ # sets the foreign keys to <tt>NULL</tt>. For, +has_many+ <tt>:through</tt>,
+ # the default strategy is +delete_all+.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets # dependent: :nullify option by default
+ # end
+ #
+ # person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.delete_all
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 0
+ # person.pets # => []
+ #
+ # Pet.find(1, 2, 3)
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: nil>,
+ # # #<Pet id: 2, name: "Spook", person_id: nil>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: nil>
+ # # ]
+ #
+ # If it is set to <tt>:destroy</tt> all the objects from the collection
+ # are removed by calling their +destroy+ method. See +destroy+ for more
+ # information.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets, dependent: :destroy
+ # end
+ #
+ # person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.delete_all
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # Pet.find(1, 2, 3)
+ # # => ActiveRecord::RecordNotFound
+ #
+ # If it is set to <tt>:delete_all</tt>, all the objects are deleted
+ # *without* calling their +destroy+ method.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets, dependent: :delete_all
+ # end
+ #
+ # person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.delete_all
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # Pet.find(1, 2, 3)
+ # # => ActiveRecord::RecordNotFound
+
+ ##
# :method: destroy_all
- # Destroy all the records from this association.
+ #
+ # Deletes the records of the collection directly from the database.
+ # This will _always_ remove the records ignoring the +:dependent+
+ # option.
#
# class Person < ActiveRecord::Base
# has_many :pets
# end
#
# person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
#
# person.pets.destroy_all
#
# person.pets.size # => 0
# person.pets # => []
+ #
+ # Pet.find(1) # => Couldn't find Pet with id=1
+
+ ##
+ # :method: destroy
+ #
+ # :call-seq:
+ # destroy(*records)
+ #
+ # Destroy the +records+ supplied and remove them from the collection.
+ # This method will _always_ remove record from the database ignoring
+ # the +:dependent+ option. Returns an array with the removed records.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.destroy(Pet.find(1))
+ # # => [#<Pet id: 1, name: "Fancy-Fancy", person_id: 1>]
+ #
+ # person.pets.size # => 2
+ # person.pets
+ # # => [
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.destroy(Pet.find(2), Pet.find(3))
+ # # => [
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 0
+ # person.pets # => []
+ #
+ # Pet.find(1, 2, 3) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (1, 2, 3)
+ #
+ # You can pass +Fixnum+ or +String+ values, it finds the records
+ # responding to the +id+ and then deletes them from the database.
+ #
+ # person.pets.size # => 3
+ # person.pets
+ # # => [
+ # # #<Pet id: 4, name: "Benny", person_id: 1>,
+ # # #<Pet id: 5, name: "Brain", person_id: 1>,
+ # # #<Pet id: 6, name: "Boss", person_id: 1>
+ # # ]
+ #
+ # person.pets.destroy("4")
+ # # => #<Pet id: 4, name: "Benny", person_id: 1>
+ #
+ # person.pets.size # => 2
+ # person.pets
+ # # => [
+ # # #<Pet id: 5, name: "Brain", person_id: 1>,
+ # # #<Pet id: 6, name: "Boss", person_id: 1>
+ # # ]
+ #
+ # person.pets.destroy(5, 6)
+ # # => [
+ # # #<Pet id: 5, name: "Brain", person_id: 1>,
+ # # #<Pet id: 6, name: "Boss", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 0
+ # person.pets # => []
+ #
+ # Pet.find(4, 5, 6) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with IDs (4, 5, 6)
+
+ ##
+ # :method: size
+ #
+ # Returns the size of the collection. If the collection hasn't been loaded,
+ # it executes a <tt>SELECT COUNT(*)</tt> query.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets.size # => 3
+ # # executes something like SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" = 1
+ #
+ # person.pets # This will execute a SELECT * FROM query
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
+ #
+ # person.pets.size # => 3
+ # # Because the collection is already loaded, this will behave like
+ # # collection.size and no SQL count query is executed.
+
+ ##
+ # :method: length
+ #
+ # Returns the size of the collection calling +size+ on the target.
+ # If the collection has been already loaded, +length+ and +size+ are
+ # equivalent.
+ #
+ # class Person < ActiveRecord::Base
+ # has_many :pets
+ # end
+ #
+ # person.pets.length # => 3
+ # # executes something like SELECT "pets".* FROM "pets" WHERE "pets"."person_id" = 1
+ #
+ # # Because the collection is loaded, you can
+ # # call the collection with no additional queries:
+ # person.pets
+ # # => [
+ # # #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
+ # # #<Pet id: 2, name: "Spook", person_id: 1>,
+ # # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
+ # # ]
##
# :method: empty?
- # Returns true if the collection is empty.
+ #
+ # Returns +true+ if the collection is empty.
#
# class Person < ActiveRecord::Base
# has_many :pets
@@ -179,7 +599,12 @@ module ActiveRecord
##
# :method: any?
- # Returns true if the collection is not empty.
+ #
+ # :call-seq:
+ # any?
+ # any?{|item| block}
+ #
+ # Returns +true+ if the collection is not empty.
#
# class Person < ActiveRecord::Base
# has_many :pets
@@ -211,8 +636,13 @@ module ActiveRecord
##
# :method: many?
+ #
+ # :call-seq:
+ # many?
+ # many?{|item| block}
+ #
# Returns true if the collection has more than one record.
- # Equivalent to +collection.size > 1+.
+ # Equivalent to <tt>collection.size > 1</tt>.
#
# class Person < ActiveRecord::Base
# has_many :pets
@@ -248,7 +678,11 @@ module ActiveRecord
##
# :method: include?
- # Returns true if the given object is present in the collection.
+ #
+ # :call-seq:
+ # include?(record)
+ #
+ # Returns +true+ if the given object is present in the collection.
#
# class Person < ActiveRecord::Base
# has_many :pets
@@ -331,37 +765,32 @@ module ActiveRecord
end
alias_method :push, :<<
- # Removes every object from the collection. This does not destroy
- # the objects, it sets their foreign keys to +NULL+. Returns +self+
- # so methods can be chained.
+ # Equivalent to +delete_all+. The difference is that returns +self+, instead
+ # of an array with the deleted objects, so methods can be chained. See
+ # +delete_all+ for more information.
+ def clear
+ delete_all
+ self
+ end
+
+ # Reloads the collection from the database. Returns +self+.
+ # Equivalent to <tt>collection(true)</tt>.
#
# class Person < ActiveRecord::Base
# has_many :pets
# end
#
- # person.pets # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
- # person.pets.clear # => []
- # person.pets.size # => 0
+ # person.pets # fetches pets from the database
+ # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
#
- # Pet.find(1) # => #<Pet id: 1, name: "Snoop", group: "dogs", person_id: nil>
+ # person.pets # uses the pets cache
+ # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
#
- # If they are associated with +dependent: :destroy+ option, it deletes
- # them directly from the database.
+ # person.pets.reload # fetches pets from the database
+ # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
#
- # class Person < ActiveRecord::Base
- # has_many :pets, dependent: :destroy
- # end
- #
- # person.pets # => [#<Pet id: 2, name: "Gorby", group: "cats", person_id: 2>]
- # person.pets.clear # => []
- # person.pets.size # => 0
- #
- # Pet.find(2) # => ActiveRecord::RecordNotFound: Couldn't find Pet with id=2
- def clear
- delete_all
- self
- end
-
+ # person.pets(true)  # fetches pets from the database
+ # # => [#<Pet id: 1, name: "Snoop", group: "dogs", person_id: 1>]
def reload
proxy_association.reload
self
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb
index fafed94ff2..54705e4950 100644
--- a/activerecord/lib/active_record/associations/preloader.rb
+++ b/activerecord/lib/active_record/associations/preloader.rb
@@ -12,7 +12,7 @@ module ActiveRecord
# and all of its books via a single query:
#
# SELECT * FROM authors
- # LEFT OUTER JOIN books ON authors.id = books.id
+ # LEFT OUTER JOIN books ON authors.id = books.author_id
# WHERE authors.name = 'Ken Akamatsu'
#
# However, this could result in many rows that contain redundant data. After
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index c6699737b4..c259e46073 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -55,12 +55,20 @@ module ActiveRecord
#
# == Options
#
- # There are two connection-pooling-related options that you can add to
+ # There are several connection-pooling-related options that you can add to
# your database connection configuration:
#
# * +pool+: number indicating size of connection pool (default 5)
- # * +wait_timeout+: number of seconds to block and wait for a connection
+ # * +checkout_timeout+: number of seconds to block and wait for a connection
# before giving up and raising a timeout error (default 5 seconds).
+ # * +reaping_frequency+: frequency in seconds to periodically run the
+ # Reaper, which attempts to find and close dead connections, which can
+ # occur if a programmer forgets to close a connection at the end of a
+ # thread or a thread dies unexpectedly. (Default nil, which means don't
+ # run the Reaper).
+ # * +dead_connection_timeout+: number of seconds from last checkout
+ # after which the Reaper will consider a connection reapable. (default
+ # 5 seconds).
class ConnectionPool
# Every +frequency+ seconds, the reaper will call +reap+ on +pool+.
# A reaper instantiated with a nil frequency will never reap the
@@ -89,7 +97,7 @@ module ActiveRecord
include MonitorMixin
- attr_accessor :automatic_reconnect, :timeout
+ attr_accessor :automatic_reconnect, :checkout_timeout, :dead_connection_timeout
attr_reader :spec, :connections, :size, :reaper
class Latch # :nodoc:
@@ -121,7 +129,8 @@ module ActiveRecord
# The cache of reserved connections mapped to threads
@reserved_connections = {}
- @timeout = spec.config[:wait_timeout] || 5
+ @checkout_timeout = spec.config[:checkout_timeout] || 5
+ @dead_connection_timeout = spec.config[:dead_connection_timeout]
@reaper = Reaper.new self, spec.config[:reaping_frequency]
@reaper.run
@@ -241,7 +250,7 @@ module ActiveRecord
return checkout_and_verify(conn) if conn
end
- Timeout.timeout(@timeout, PoolFullError) { @latch.await }
+ Timeout.timeout(@checkout_timeout, PoolFullError) { @latch.await }
end
end
@@ -279,7 +288,7 @@ module ActiveRecord
# or a thread dies unexpectedly.
def reap
synchronize do
- stale = Time.now - @timeout
+ stale = Time.now - @dead_connection_timeout
connections.dup.each do |conn|
remove conn if conn.in_use? && stale > conn.last_use && !conn.active?
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 15c3d7be36..d62cf529a4 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -18,7 +18,7 @@ module ActiveRecord
# Forward any unused config params to PGconn.connect.
[:statement_limit, :encoding, :min_messages, :schema_search_path,
- :schema_order, :adapter, :pool, :wait_timeout, :template,
+ :schema_order, :adapter, :pool, :checkout_timeout, :template,
:reaping_frequency, :insert_returning].each do |key|
conn_params.delete key
end
@@ -1274,7 +1274,7 @@ module ActiveRecord
end
when 'integer'
return 'integer' unless limit
-
+
case limit
when 1, 2; 'smallint'
when 3, 4; 'integer'
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 8dc9f761c2..bba7815d73 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -124,7 +124,7 @@ module ActiveRecord
@pool.checkout
@pool.checkout
@pool.checkout
- @pool.timeout = 0
+ @pool.dead_connection_timeout = 0
connections = @pool.connections.dup
@@ -137,7 +137,7 @@ module ActiveRecord
@pool.checkout
@pool.checkout
@pool.checkout
- @pool.timeout = 0
+ @pool.dead_connection_timeout = 0
connections = @pool.connections.dup
connections.each do |conn|
diff --git a/activerecord/test/cases/pooled_connections_test.rb b/activerecord/test/cases/pooled_connections_test.rb
index fba3006ebe..0a6354f5cc 100644
--- a/activerecord/test/cases/pooled_connections_test.rb
+++ b/activerecord/test/cases/pooled_connections_test.rb
@@ -17,7 +17,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
end
def checkout_connections
- ActiveRecord::Model.establish_connection(@connection.merge({:pool => 2, :wait_timeout => 0.3}))
+ ActiveRecord::Model.establish_connection(@connection.merge({:pool => 2, :checkout_timeout => 0.3}))
@connections = []
@timed_out = 0
@@ -34,7 +34,7 @@ class PooledConnectionsTest < ActiveRecord::TestCase
# Will deadlock due to lack of Monitor timeouts in 1.9
def checkout_checkin_connections(pool_size, threads)
- ActiveRecord::Model.establish_connection(@connection.merge({:pool => pool_size, :wait_timeout => 0.5}))
+ ActiveRecord::Model.establish_connection(@connection.merge({:pool => pool_size, :checkout_timeout => 0.5}))
@connection_count = 0
@timed_out = 0
threads.times do
diff --git a/activerecord/test/cases/reaper_test.rb b/activerecord/test/cases/reaper_test.rb
index 576ab60090..e53a27d5dd 100644
--- a/activerecord/test/cases/reaper_test.rb
+++ b/activerecord/test/cases/reaper_test.rb
@@ -64,7 +64,7 @@ module ActiveRecord
spec.config[:reaping_frequency] = 0.0001
pool = ConnectionPool.new spec
- pool.timeout = 0
+ pool.dead_connection_timeout = 0
conn = pool.checkout
count = pool.connections.length
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec
index 2c874e932e..30221f2401 100644
--- a/activesupport/activesupport.gemspec
+++ b/activesupport/activesupport.gemspec
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
s.description = 'A toolkit of support libraries and Ruby core extensions extracted from the Rails framework. Rich support for multibyte strings, internationalization, time zones, and testing.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/guides/assets/images/belongs_to.png b/guides/assets/images/belongs_to.png
index 44243edbca..43c963ffa8 100644
--- a/guides/assets/images/belongs_to.png
+++ b/guides/assets/images/belongs_to.png
Binary files differ
diff --git a/guides/assets/images/book_icon.gif b/guides/assets/images/book_icon.gif
index c81d5db520..efc5e06880 100644
--- a/guides/assets/images/book_icon.gif
+++ b/guides/assets/images/book_icon.gif
Binary files differ
diff --git a/guides/assets/images/challenge.png b/guides/assets/images/challenge.png
index d163748640..30be3d7028 100644
--- a/guides/assets/images/challenge.png
+++ b/guides/assets/images/challenge.png
Binary files differ
diff --git a/guides/assets/images/chapters_icon.gif b/guides/assets/images/chapters_icon.gif
index 06fb415f4a..a61c28c02d 100644
--- a/guides/assets/images/chapters_icon.gif
+++ b/guides/assets/images/chapters_icon.gif
Binary files differ
diff --git a/guides/assets/images/check_bullet.gif b/guides/assets/images/check_bullet.gif
index 1fcfeba250..bd54ef64c9 100644
--- a/guides/assets/images/check_bullet.gif
+++ b/guides/assets/images/check_bullet.gif
Binary files differ
diff --git a/guides/assets/images/credits_pic_blank.gif b/guides/assets/images/credits_pic_blank.gif
index f6f654fc65..a6b335d0c9 100644
--- a/guides/assets/images/credits_pic_blank.gif
+++ b/guides/assets/images/credits_pic_blank.gif
Binary files differ
diff --git a/guides/assets/images/csrf.png b/guides/assets/images/csrf.png
index ab73baafe8..a8123d47c3 100644
--- a/guides/assets/images/csrf.png
+++ b/guides/assets/images/csrf.png
Binary files differ
diff --git a/guides/assets/images/customized_error_messages.png b/guides/assets/images/customized_error_messages.png
index fa676991e3..fcf47b4be0 100644
--- a/guides/assets/images/customized_error_messages.png
+++ b/guides/assets/images/customized_error_messages.png
Binary files differ
diff --git a/guides/assets/images/edge_badge.png b/guides/assets/images/edge_badge.png
index cddd46c4b8..a35dc9f8ee 100644
--- a/guides/assets/images/edge_badge.png
+++ b/guides/assets/images/edge_badge.png
Binary files differ
diff --git a/guides/assets/images/error_messages.png b/guides/assets/images/error_messages.png
index 428892194a..1189e486d4 100644
--- a/guides/assets/images/error_messages.png
+++ b/guides/assets/images/error_messages.png
Binary files differ
diff --git a/guides/assets/images/getting_started/confirm_dialog.png b/guides/assets/images/getting_started/confirm_dialog.png
index a26c09ef2d..1a13eddd91 100644
--- a/guides/assets/images/getting_started/confirm_dialog.png
+++ b/guides/assets/images/getting_started/confirm_dialog.png
Binary files differ
diff --git a/guides/assets/images/getting_started/form_with_errors.png b/guides/assets/images/getting_started/form_with_errors.png
index badefe6ea6..6910e1647e 100644
--- a/guides/assets/images/getting_started/form_with_errors.png
+++ b/guides/assets/images/getting_started/form_with_errors.png
Binary files differ
diff --git a/guides/assets/images/getting_started/index_action_with_edit_link.png b/guides/assets/images/getting_started/index_action_with_edit_link.png
index 6e58a13756..bf23cba231 100644
--- a/guides/assets/images/getting_started/index_action_with_edit_link.png
+++ b/guides/assets/images/getting_started/index_action_with_edit_link.png
Binary files differ
diff --git a/guides/assets/images/getting_started/new_post.png b/guides/assets/images/getting_started/new_post.png
index dc9459032a..b573cb164c 100644
--- a/guides/assets/images/getting_started/new_post.png
+++ b/guides/assets/images/getting_started/new_post.png
Binary files differ
diff --git a/guides/assets/images/getting_started/post_with_comments.png b/guides/assets/images/getting_started/post_with_comments.png
index bd9b2e10f5..e13095ff8f 100644
--- a/guides/assets/images/getting_started/post_with_comments.png
+++ b/guides/assets/images/getting_started/post_with_comments.png
Binary files differ
diff --git a/guides/assets/images/getting_started/routing_error_no_controller.png b/guides/assets/images/getting_started/routing_error_no_controller.png
index 92a39efd78..407ea2ea06 100644
--- a/guides/assets/images/getting_started/routing_error_no_controller.png
+++ b/guides/assets/images/getting_started/routing_error_no_controller.png
Binary files differ
diff --git a/guides/assets/images/getting_started/routing_error_no_route_matches.png b/guides/assets/images/getting_started/routing_error_no_route_matches.png
index bc768a94a2..d461807c5d 100644
--- a/guides/assets/images/getting_started/routing_error_no_route_matches.png
+++ b/guides/assets/images/getting_started/routing_error_no_route_matches.png
Binary files differ
diff --git a/guides/assets/images/getting_started/show_action_for_posts.png b/guides/assets/images/getting_started/show_action_for_posts.png
index 5c8c4d8e5e..9467df6a07 100644
--- a/guides/assets/images/getting_started/show_action_for_posts.png
+++ b/guides/assets/images/getting_started/show_action_for_posts.png
Binary files differ
diff --git a/guides/assets/images/getting_started/template_is_missing_posts_new.png b/guides/assets/images/getting_started/template_is_missing_posts_new.png
index 9f070d59db..6860aaeca7 100644
--- a/guides/assets/images/getting_started/template_is_missing_posts_new.png
+++ b/guides/assets/images/getting_started/template_is_missing_posts_new.png
Binary files differ
diff --git a/guides/assets/images/getting_started/undefined_method_post_path.png b/guides/assets/images/getting_started/undefined_method_post_path.png
index f568bf315c..c29cb2f54f 100644
--- a/guides/assets/images/getting_started/undefined_method_post_path.png
+++ b/guides/assets/images/getting_started/undefined_method_post_path.png
Binary files differ
diff --git a/guides/assets/images/getting_started/unknown_action_create_for_posts.png b/guides/assets/images/getting_started/unknown_action_create_for_posts.png
index 03d92dfb7d..1eca14b988 100644
--- a/guides/assets/images/getting_started/unknown_action_create_for_posts.png
+++ b/guides/assets/images/getting_started/unknown_action_create_for_posts.png
Binary files differ
diff --git a/guides/assets/images/getting_started/unknown_action_new_for_posts.png b/guides/assets/images/getting_started/unknown_action_new_for_posts.png
index b63883d922..fd72586573 100644
--- a/guides/assets/images/getting_started/unknown_action_new_for_posts.png
+++ b/guides/assets/images/getting_started/unknown_action_new_for_posts.png
Binary files differ
diff --git a/guides/assets/images/grey_bullet.gif b/guides/assets/images/grey_bullet.gif
index e75e8e93a1..3c08b1571c 100644
--- a/guides/assets/images/grey_bullet.gif
+++ b/guides/assets/images/grey_bullet.gif
Binary files differ
diff --git a/guides/assets/images/habtm.png b/guides/assets/images/habtm.png
index fea78b0b5c..b062bc73fe 100644
--- a/guides/assets/images/habtm.png
+++ b/guides/assets/images/habtm.png
Binary files differ
diff --git a/guides/assets/images/has_many.png b/guides/assets/images/has_many.png
index 6cff58460d..e7589e3b75 100644
--- a/guides/assets/images/has_many.png
+++ b/guides/assets/images/has_many.png
Binary files differ
diff --git a/guides/assets/images/has_many_through.png b/guides/assets/images/has_many_through.png
index 85d7599925..858c898dc1 100644
--- a/guides/assets/images/has_many_through.png
+++ b/guides/assets/images/has_many_through.png
Binary files differ
diff --git a/guides/assets/images/has_one.png b/guides/assets/images/has_one.png
index a70ddaaa86..93faa05b07 100644
--- a/guides/assets/images/has_one.png
+++ b/guides/assets/images/has_one.png
Binary files differ
diff --git a/guides/assets/images/has_one_through.png b/guides/assets/images/has_one_through.png
index 89a7617a30..07dac1a27d 100644
--- a/guides/assets/images/has_one_through.png
+++ b/guides/assets/images/has_one_through.png
Binary files differ
diff --git a/guides/assets/images/header_backdrop.png b/guides/assets/images/header_backdrop.png
index ff2982175e..72b030478f 100644
--- a/guides/assets/images/header_backdrop.png
+++ b/guides/assets/images/header_backdrop.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_html_safe.png b/guides/assets/images/i18n/demo_html_safe.png
index f881f60dac..9afa8ebec1 100644
--- a/guides/assets/images/i18n/demo_html_safe.png
+++ b/guides/assets/images/i18n/demo_html_safe.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_localized_pirate.png b/guides/assets/images/i18n/demo_localized_pirate.png
index 9134709573..bf8d0b558c 100644
--- a/guides/assets/images/i18n/demo_localized_pirate.png
+++ b/guides/assets/images/i18n/demo_localized_pirate.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_translated_en.png b/guides/assets/images/i18n/demo_translated_en.png
index ecdd878d38..e887bfa306 100644
--- a/guides/assets/images/i18n/demo_translated_en.png
+++ b/guides/assets/images/i18n/demo_translated_en.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_translated_pirate.png b/guides/assets/images/i18n/demo_translated_pirate.png
index 41c580923a..aa5618a865 100644
--- a/guides/assets/images/i18n/demo_translated_pirate.png
+++ b/guides/assets/images/i18n/demo_translated_pirate.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_translation_missing.png b/guides/assets/images/i18n/demo_translation_missing.png
index af9e2d0427..867aa7c42d 100644
--- a/guides/assets/images/i18n/demo_translation_missing.png
+++ b/guides/assets/images/i18n/demo_translation_missing.png
Binary files differ
diff --git a/guides/assets/images/i18n/demo_untranslated.png b/guides/assets/images/i18n/demo_untranslated.png
index 3603f43463..2ea6404822 100644
--- a/guides/assets/images/i18n/demo_untranslated.png
+++ b/guides/assets/images/i18n/demo_untranslated.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/1.png b/guides/assets/images/icons/callouts/1.png
index 7d473430b7..c5d02adcf4 100644
--- a/guides/assets/images/icons/callouts/1.png
+++ b/guides/assets/images/icons/callouts/1.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/10.png b/guides/assets/images/icons/callouts/10.png
index 997bbc8246..fe89f9ef83 100644
--- a/guides/assets/images/icons/callouts/10.png
+++ b/guides/assets/images/icons/callouts/10.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/11.png b/guides/assets/images/icons/callouts/11.png
index ce47dac3f5..9244a1ac4b 100644
--- a/guides/assets/images/icons/callouts/11.png
+++ b/guides/assets/images/icons/callouts/11.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/12.png b/guides/assets/images/icons/callouts/12.png
index 31daf4e2f2..ae56459f4c 100644
--- a/guides/assets/images/icons/callouts/12.png
+++ b/guides/assets/images/icons/callouts/12.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/13.png b/guides/assets/images/icons/callouts/13.png
index 14021a89c2..1181f9f892 100644
--- a/guides/assets/images/icons/callouts/13.png
+++ b/guides/assets/images/icons/callouts/13.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/14.png b/guides/assets/images/icons/callouts/14.png
index 64014b75fe..4274e6580a 100644
--- a/guides/assets/images/icons/callouts/14.png
+++ b/guides/assets/images/icons/callouts/14.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/15.png b/guides/assets/images/icons/callouts/15.png
index 0d65765fcf..39304de94f 100644
--- a/guides/assets/images/icons/callouts/15.png
+++ b/guides/assets/images/icons/callouts/15.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/2.png b/guides/assets/images/icons/callouts/2.png
index 5d09341b2f..8c57970ba9 100644
--- a/guides/assets/images/icons/callouts/2.png
+++ b/guides/assets/images/icons/callouts/2.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/3.png b/guides/assets/images/icons/callouts/3.png
index ef7b700471..57a33d15b4 100644
--- a/guides/assets/images/icons/callouts/3.png
+++ b/guides/assets/images/icons/callouts/3.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/4.png b/guides/assets/images/icons/callouts/4.png
index adb8364eb5..f061ab02b8 100644
--- a/guides/assets/images/icons/callouts/4.png
+++ b/guides/assets/images/icons/callouts/4.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/5.png b/guides/assets/images/icons/callouts/5.png
index 4d7eb46002..b4de02da11 100644
--- a/guides/assets/images/icons/callouts/5.png
+++ b/guides/assets/images/icons/callouts/5.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/6.png b/guides/assets/images/icons/callouts/6.png
index 0ba694af6c..0e055eec1e 100644
--- a/guides/assets/images/icons/callouts/6.png
+++ b/guides/assets/images/icons/callouts/6.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/7.png b/guides/assets/images/icons/callouts/7.png
index 472e96f8ac..5ead87d040 100644
--- a/guides/assets/images/icons/callouts/7.png
+++ b/guides/assets/images/icons/callouts/7.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/8.png b/guides/assets/images/icons/callouts/8.png
index 5e60973c21..cb99545eb6 100644
--- a/guides/assets/images/icons/callouts/8.png
+++ b/guides/assets/images/icons/callouts/8.png
Binary files differ
diff --git a/guides/assets/images/icons/callouts/9.png b/guides/assets/images/icons/callouts/9.png
index a0676d26cc..0ac03602f6 100644
--- a/guides/assets/images/icons/callouts/9.png
+++ b/guides/assets/images/icons/callouts/9.png
Binary files differ
diff --git a/guides/assets/images/icons/caution.png b/guides/assets/images/icons/caution.png
index cb9d5ea0df..031e19c776 100644
--- a/guides/assets/images/icons/caution.png
+++ b/guides/assets/images/icons/caution.png
Binary files differ
diff --git a/guides/assets/images/icons/example.png b/guides/assets/images/icons/example.png
index bba1c0010d..1b0e482059 100644
--- a/guides/assets/images/icons/example.png
+++ b/guides/assets/images/icons/example.png
Binary files differ
diff --git a/guides/assets/images/icons/home.png b/guides/assets/images/icons/home.png
index 37a5231bac..24149d6e78 100644
--- a/guides/assets/images/icons/home.png
+++ b/guides/assets/images/icons/home.png
Binary files differ
diff --git a/guides/assets/images/icons/important.png b/guides/assets/images/icons/important.png
index 1096c23295..dafcf0f59e 100644
--- a/guides/assets/images/icons/important.png
+++ b/guides/assets/images/icons/important.png
Binary files differ
diff --git a/guides/assets/images/icons/next.png b/guides/assets/images/icons/next.png
index 64e126bdda..355b329f5a 100644
--- a/guides/assets/images/icons/next.png
+++ b/guides/assets/images/icons/next.png
Binary files differ
diff --git a/guides/assets/images/icons/note.png b/guides/assets/images/icons/note.png
index 841820f7c4..08d35a6f5c 100644
--- a/guides/assets/images/icons/note.png
+++ b/guides/assets/images/icons/note.png
Binary files differ
diff --git a/guides/assets/images/icons/prev.png b/guides/assets/images/icons/prev.png
index 3e8f12fe24..ea564c865e 100644
--- a/guides/assets/images/icons/prev.png
+++ b/guides/assets/images/icons/prev.png
Binary files differ
diff --git a/guides/assets/images/icons/tip.png b/guides/assets/images/icons/tip.png
index a3a029d898..d834e6d1bb 100644
--- a/guides/assets/images/icons/tip.png
+++ b/guides/assets/images/icons/tip.png
Binary files differ
diff --git a/guides/assets/images/icons/up.png b/guides/assets/images/icons/up.png
index 2db1ce62fa..379f0045af 100644
--- a/guides/assets/images/icons/up.png
+++ b/guides/assets/images/icons/up.png
Binary files differ
diff --git a/guides/assets/images/icons/warning.png b/guides/assets/images/icons/warning.png
index 0b0c419df2..72a8a5d873 100644
--- a/guides/assets/images/icons/warning.png
+++ b/guides/assets/images/icons/warning.png
Binary files differ
diff --git a/guides/assets/images/nav_arrow.gif b/guides/assets/images/nav_arrow.gif
index c4f57658d7..ff081819ad 100644
--- a/guides/assets/images/nav_arrow.gif
+++ b/guides/assets/images/nav_arrow.gif
Binary files differ
diff --git a/guides/assets/images/oscardelben.jpg b/guides/assets/images/oscardelben.jpg
new file mode 100644
index 0000000000..9f3f67c2c7
--- /dev/null
+++ b/guides/assets/images/oscardelben.jpg
Binary files differ
diff --git a/guides/assets/images/polymorphic.png b/guides/assets/images/polymorphic.png
index ff2fd9f76d..a3cbc4502a 100644
--- a/guides/assets/images/polymorphic.png
+++ b/guides/assets/images/polymorphic.png
Binary files differ
diff --git a/guides/assets/images/rails_guides_logo.gif b/guides/assets/images/rails_guides_logo.gif
index a24683a34e..9b0ad5af28 100644
--- a/guides/assets/images/rails_guides_logo.gif
+++ b/guides/assets/images/rails_guides_logo.gif
Binary files differ
diff --git a/guides/assets/images/rails_welcome.png b/guides/assets/images/rails_welcome.png
index f2aa210d19..8ad2d351de 100644
--- a/guides/assets/images/rails_welcome.png
+++ b/guides/assets/images/rails_welcome.png
Binary files differ
diff --git a/guides/assets/images/session_fixation.png b/guides/assets/images/session_fixation.png
index 6b084508db..ac3ab01614 100644
--- a/guides/assets/images/session_fixation.png
+++ b/guides/assets/images/session_fixation.png
Binary files differ
diff --git a/guides/assets/images/tab_grey.gif b/guides/assets/images/tab_grey.gif
index e9680b7136..995adb76cf 100644
--- a/guides/assets/images/tab_grey.gif
+++ b/guides/assets/images/tab_grey.gif
Binary files differ
diff --git a/guides/assets/images/tab_info.gif b/guides/assets/images/tab_info.gif
index 458fea9a61..e9dd164f18 100644
--- a/guides/assets/images/tab_info.gif
+++ b/guides/assets/images/tab_info.gif
Binary files differ
diff --git a/guides/assets/images/tab_note.gif b/guides/assets/images/tab_note.gif
index 1d5c171ed6..f9b546c6f8 100644
--- a/guides/assets/images/tab_note.gif
+++ b/guides/assets/images/tab_note.gif
Binary files differ
diff --git a/guides/assets/images/tab_red.gif b/guides/assets/images/tab_red.gif
index daf140b5a8..0613093ddc 100644
--- a/guides/assets/images/tab_red.gif
+++ b/guides/assets/images/tab_red.gif
Binary files differ
diff --git a/guides/assets/images/tab_yellow.gif b/guides/assets/images/tab_yellow.gif
index dc961c99dd..39a3c2dc6a 100644
--- a/guides/assets/images/tab_yellow.gif
+++ b/guides/assets/images/tab_yellow.gif
Binary files differ
diff --git a/guides/assets/images/tab_yellow.png b/guides/assets/images/tab_yellow.png
index cceea6581f..3ab1c56c4d 100644
--- a/guides/assets/images/tab_yellow.png
+++ b/guides/assets/images/tab_yellow.png
Binary files differ
diff --git a/guides/assets/images/validation_error_messages.png b/guides/assets/images/validation_error_messages.png
index 622d35da5d..30e4ca4a3d 100644
--- a/guides/assets/images/validation_error_messages.png
+++ b/guides/assets/images/validation_error_messages.png
Binary files differ
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index f114075cae..af46538bf5 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -585,7 +585,7 @@ After loading the framework and any gems in your application, Rails turns to loa
NOTE: You can use subfolders to organize your initializers if you like, because Rails will look into the whole file hierarchy from the initializers folder on down.
-TIP: If you have any ordering dependency in your initializers, you can control the load order by naming. For example, +01_critical.rb+ will be loaded before +02_normal.rb+.
+TIP: If you have any ordering dependency in your initializers, you can control the load order through naming. Initializer files are loaded in alphabetical order by their path. For example, +01_critical.rb+ will be loaded before +02_normal.rb+.
h3. Initialization events
diff --git a/guides/source/credits.html.erb b/guides/source/credits.html.erb
index da6bd6acdf..04deec6a11 100644
--- a/guides/source/credits.html.erb
+++ b/guides/source/credits.html.erb
@@ -31,6 +31,10 @@ Ruby on Rails Guides: Credits
Ryan Bigg works as a consultant at <a href="http://rubyx.com">RubyX</a> and has been working with Rails since 2006. He's co-authoring a book called <a href="http://manning.com/katz">Rails 3 in Action</a> and he's written many gems which can be seen on <a href="http://github.com/radar">his GitHub page</a> and he also tweets prolifically as <a href="http://twitter.com/ryanbigg">@ryanbigg</a>.
<% end %>
+<%= author('Oscar Del Ben', 'oscardelben', 'oscardelben.jpg') do %>
+Oscar Del Ben is a software engineer at <a href="http://www.wildfireapp.com/">Wildfire</a>. He's a regular open source contributor (<a href="https://github.com/oscardelben">Github account</a>) and tweets regularly at <a href="https://twitter.com/oscardelben">@oscardelben</a>.
+ <% end %>
+
<%= author('Frederick Cheung', 'fcheung') do %>
Frederick Cheung is Chief Wizard at Texperts where he has been using Rails since 2006. He is based in Cambridge (UK) and when not consuming fine ales he blogs at <a href="http://www.spacevatican.org">spacevatican.org</a>.
<% end %>
diff --git a/guides/source/debugging_rails_applications.textile b/guides/source/debugging_rails_applications.textile
index 45fa4ada78..0802a2db26 100644
--- a/guides/source/debugging_rails_applications.textile
+++ b/guides/source/debugging_rails_applications.textile
@@ -698,7 +698,7 @@ There are some Rails plugins to help you to find errors and debug your applicati
h3. References
-* "ruby-debug Homepage":http://www.datanoise.com/ruby-debug
+* "ruby-debug Homepage":http://bashdb.sourceforge.net/ruby-debug/home-page.html
* "debugger Homepage":http://github.com/cldwalker/debugger
* "Article: Debugging a Rails application with ruby-debug":http://www.sitepoint.com/article/debug-rails-app-ruby-debug/
* "ruby-debug Basics screencast":http://brian.maybeyoureinsane.net/blog/2007/05/07/ruby-debug-basics-screencast/
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index e25dac22da..c129aeb2e1 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -13,8 +13,6 @@ endprologue.
WARNING. This Guide is based on Rails 3.2. Some of the code shown here will not
work in earlier versions of Rails.
-WARNING: The Edge version of this guide is currently being re-worked. Please excuse us while we re-arrange the place.
-
h3. Guide Assumptions
This guide is designed for beginners who want to get started with a Rails
diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile
index 155a439e64..12b2eb7458 100644
--- a/guides/source/initialization.textile
+++ b/guides/source/initialization.textile
@@ -1,13 +1,15 @@
h2. The Rails Initialization Process
-This guide explains the internals of the initialization process in Rails as of Rails 3.1. It is an extremely in-depth guide and recommended for advanced Rails developers.
+This guide explains the internals of the initialization process in Rails
+as of Rails 4. It is an extremely in-depth guide and recommended for advanced Rails developers.
* Using +rails server+
* Using Passenger
endprologue.
-This guide goes through every single file, class and method call that is required to boot up the Ruby on Rails stack for a default Rails 3.1 application, explaining each part in detail along the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application.
+This guide goes through every single file, class and method call that is
+required to boot up the Ruby on Rails stack for a default Rails 4 application, explaining each part in detail along the way. For this guide, we will be focusing on how the two most common methods (+rails server+ and Passenger) boot a Rails application.
NOTE: Paths in this guide are relative to Rails or a Rails application unless otherwise specified.
@@ -22,16 +24,15 @@ The actual +rails+ command is kept in _bin/rails_:
<ruby>
#!/usr/bin/env ruby
-begin
- require "rails/cli"
-rescue LoadError
- railties_path = File.expand_path('../../railties/lib', __FILE__)
+if File.exists?(File.join(File.expand_path('../../..', __FILE__), '.git'))
+ railties_path = File.expand_path('../../lib', __FILE__)
$:.unshift(railties_path)
- require "rails/cli"
end
+require "rails/cli"
</ruby>
-This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying.
+This file will first attempt to push the +railties/lib+ directory if
+present, and then require +rails/cli+.
h4. +railties/lib/rails/cli.rb+
@@ -46,7 +47,7 @@ require 'rails/script_rails_loader'
Rails::ScriptRailsLoader.exec_script_rails!
require 'rails/ruby_version_check'
-Signal.trap("INT") { puts; exit }
+Signal.trap("INT") { puts; exit(1) }
if ARGV.first == 'plugin'
ARGV.shift
@@ -56,7 +57,7 @@ else
end
</ruby>
-The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see this in use in +railties/lib/rails/script_rails_loader+.
+The +rbconfig+ file from the Ruby standard library provides us with the +RbConfig+ class which contains detailed information about the Ruby environment, including how Ruby was compiled. We can see thisin use in +railties/lib/rails/script_rails_loader+.
<ruby>
require 'pathname'
@@ -120,6 +121,9 @@ exec RUBY, SCRIPT_RAILS, *ARGV if in_rails_application?
This is effectively the same as running +ruby script/rails [arguments]+, where +[arguments]+ at this point in time is simply "server".
+TIP: If you execute +script/rails+ directly from your Rails app you will
+avoid executing the code that we just described.
+
h4. +script/rails+
This file is as follows:
@@ -134,23 +138,23 @@ The +APP_PATH+ constant will be used later in +rails/commands+. The +config/boot
h4. +config/boot.rb+
-+config/boot.rb+ contains this:
++config/boot.rb+ contains:
<ruby>
# Set up gems listed in the Gemfile.
-gemfile = File.expand_path('../../Gemfile', __FILE__)
-begin
- ENV['BUNDLE_GEMFILE'] = gemfile
- require 'bundler'
- Bundler.setup
-rescue Bundler::GemNotFound => e
- STDERR.puts e.message
- STDERR.puts "Try running `bundle install`."
- exit!
-end if File.exist?(gemfile)
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
</ruby>
-In a standard Rails application, there's a +Gemfile+ which declares all dependencies of the application. +config/boot.rb+ sets +ENV["BUNDLE_GEMFILE"]+ to the location of this file, then requires Bundler and calls +Bundler.setup+ which adds the dependencies of the application (including all the Rails parts) to the load path, making them available for the application to load. The gems that a Rails 3.1 application depends on are as follows:
+In a standard Rails application, there's a +Gemfile+ which declares all
+dependencies of the application. +config/boot.rb+ sets
++ENV['BUNDLE_GEMFILE']+ to the location of this file. If the Gemfile
+exists, +bundler/setup+ is then required.
+
+The gems that a Rails 4 application depends on are as follows:
+
+TODO: change these when the Rails 4 release is near.
* abstract (1.0.0)
* actionmailer (3.1.0.beta)
@@ -183,6 +187,8 @@ h4. +rails/commands.rb+
Once +config/boot.rb+ has finished, the next file that is required is +rails/commands+ which will execute a command based on the arguments passed in. In this case, the +ARGV+ array simply contains +server+ which is extracted into the +command+ variable using these lines:
<ruby>
+ARGV << '--help' if ARGV.empty?
+
aliases = {
"g" => "generate",
"c" => "console",
@@ -195,6 +201,9 @@ command = ARGV.shift
command = aliases[command] || command
</ruby>
+TIP: As you can see, an empty ARGV list will make Rails show the help
+snippet.
+
If we used <tt>s</tt> rather than +server+, Rails will use the +aliases+ defined in the file and match them to their respective commands. With the +server+ command, Rails will run this code:
<ruby>
@@ -361,8 +370,9 @@ This method is defined like this:
<ruby>
def start
+ url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
- puts "=> Rails #{Rails.version} application starting in #{Rails.env} on http://#{options[:Host]}:#{options[:Port]}"
+ puts "=> Rails #{Rails.version} application starting in #{Rails.env} on #{url}"
puts "=> Call with -d to detach" unless options[:daemonize]
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
@@ -372,6 +382,15 @@ def start
FileUtils.mkdir_p(Rails.root.join('tmp', dir_to_make))
end
+ unless options[:daemonize]
+ wrapped_app # touch the app so the logger is set up
+
+ console = ActiveSupport::Logger.new($stdout)
+ console.formatter = Rails.logger.formatter
+
+ Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
+ end
+
super
ensure
# The '-h' option calls exit before @options is set.
@@ -380,10 +399,18 @@ ensure
end
</ruby>
-This is where the first output of the Rails initialization happens. This method creates a trap for +INT+ signals, so if you +CTRL+C+ the server, it will exit the process. As we can see from the code here, it will create the +tmp/cache+, +tmp/pids+, +tmp/sessions+ and +tmp/sockets+ directories if they don't already exist prior to calling +super+. The +super+ method will call +Rack::Server.start+ which begins its definition like this:
+This is where the first output of the Rails initialization happens. This
+method creates a trap for +INT+ signals, so if you +CTRL-C+ the server,
+it will exit the process. As we can see from the code here, it will
+create the +tmp/cache+, +tmp/pids+, +tmp/sessions+ and +tmp/sockets+
+directories. It then calls +wrapped_app+ which is responsible for
+creating the Rack app, before creating and assignig an
+instance of +ActiveSupport::Logger+.
+
+The +super+ method will call +Rack::Server.start+ which begins its definition like this:
<ruby>
-def start
+def start &blk
if options[:warn]
$-w = true
end
@@ -403,22 +430,37 @@ def start
pp wrapped_app
pp app
end
-end
-</ruby>
-In a Rails application, these options are not set at all and therefore aren't used at all. The first line of code that's executed in this method is a call to this method:
+ check_pid! if options[:pid]
-<ruby>
-wrapped_app
+ # Touch the wrapped app, so that the config.ru is loaded before
+ # daemonization (i.e. before chdir, etc).
+ wrapped_app
+
+ daemonize_app if options[:daemonize]
+
+ write_pid if options[:pid]
+
+ trap(:INT) do
+ if server.respond_to?(:shutdown)
+ server.shutdown
+ else
+ exit
+ end
+ end
+
+ server.run wrapped_app, options, &blk
+end
</ruby>
-This method calls another method:
+The interesting part for a Rails app is the last line, +server.run+. Here we encounter the +wrapped_app+ method again, which this time
+we're going to explore more.
<ruby>
@wrapped_app ||= build_app app
</ruby>
-Then the +app+ method here is defined like so:
+The +app+ method here is defined like so:
<ruby>
def app
@@ -440,7 +482,7 @@ The +options[:config]+ value defaults to +config.ru+ which contains this:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
-run YourApp::Application
+run <%= app_const %>
</ruby>
diff --git a/rails.gemspec b/rails.gemspec
index 8314036ad1..52f92f46c6 100644
--- a/rails.gemspec
+++ b/rails.gemspec
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.9.3'
s.required_rubygems_version = ">= 1.8.11"
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index 92f40b9e31..c41acc7841 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -5,8 +5,7 @@ module Rails
module Generators
module Actions
- # Adds an entry into Gemfile for the supplied gem. If env
- # is specified, add the gem to the given environment.
+ # Adds an entry into Gemfile for the supplied gem.
#
# gem "rspec", :group => :test
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
diff --git a/railties/railties.gemspec b/railties/railties.gemspec
index 7067253279..2a39826c8d 100644
--- a/railties/railties.gemspec
+++ b/railties/railties.gemspec
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
s.summary = 'Tools for creating, working with, and running Rails applications.'
s.description = 'Rails internals: application bootup, plugins, generators, and rake tasks.'
s.required_ruby_version = '>= 1.9.3'
+ s.license = 'MIT'
s.author = 'David Heinemeier Hansson'
s.email = 'david@loudthinking.com'