diff options
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 6 | ||||
-rw-r--r-- | activerecord/lib/active_record/nested_attributes.rb | 28 | ||||
-rw-r--r-- | railties/guides/source/plugins.textile | 2 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 2 |
4 files changed, 33 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index 237cd56683..ed0d4aef7f 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -56,15 +56,15 @@ module ActiveRecord # Post.update_counters 5, :comment_count => -1, :action_count => 1 # # Executes the following SQL: # # UPDATE posts - # # SET comment_count = comment_count - 1, - # # action_count = action_count + 1 + # # SET comment_count = COALESCE(comment_count, 0) - 1, + # # action_count = COALESCE(action_count, 0) + 1 # # WHERE id = 5 # # # For the Posts with id of 10 and 15, increment the comment_count by 1 # Post.update_counters [10, 15], :comment_count => 1 # # Executes the following SQL: # # UPDATE posts - # # SET comment_count = comment_count + 1, + # # SET comment_count = COALESCE(comment_count, 0) + 1, # # WHERE id IN (10, 15) def update_counters(id, counters) updates = counters.map do |counter_name, value| diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 520969adbb..33611b410c 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -190,6 +190,34 @@ module ActiveRecord # destruction, are saved and destroyed automatically and atomically when # the parent model is saved. This happens inside the transaction initiated # by the parents save method. See ActiveRecord::AutosaveAssociation. + # + # === Using with attr_accessible + # + # The use of <tt>attr_accessible</tt> can interfere with nested attributes + # if you're not careful. For example, if the <tt>Member</tt> model above + # was using <tt>attr_accessible</tt> like this: + # + # attr_accessible :name + # + # You would need to modify it to look like this: + # + # attr_accessible :name, :posts_attributes + # + # === Validating the presence of a parent model + # + # If you want to validate that a child record is associated with a parent + # record, you can use <tt>validates_presence_of</tt> and + # <tt>inverse_of</tt> as this example illustrates: + # + # class Member < ActiveRecord::Base + # has_many :posts, :inverse_of => :member + # accepts_nested_attributes_for :posts + # end + # + # class Post < ActiveRecord::Base + # belongs_to :member, :inverse_of => :posts + # validates_presence_of :member + # end module ClassMethods REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |_, value| value.blank? } } diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index f89043f216..2300786791 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -1341,7 +1341,7 @@ h3. Plugins as Gems Turning your rails plugin into a gem is a simple and straightforward task. This section will cover how to turn your plugin into a gem. It will not cover how to distribute that gem. -The initialization file has to be called +rails/init.rb+, the root +init.rb+ file, if any, is ignored by Rails. Also, the name of the plugin now is relevant since +config.gem+ tries to load it. Either name the main file after your gem, or document that users should use the +:lib+ option. +Rails 3 ignores both <tt>init.rb</tt> and <tt>rails/init.rb</tt> file of a gem. Also, the name of the plugin now is relevant since +config.gem+ tries to load it. Either name the main file after your gem, or document that users should use the +:lib+ option. It's common practice to put any developer-centric rake tasks (such as tests, rdoc and gem package tasks) in +Rakefile+. A rake task that packages the gem might look like this: diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 2684552701..58b0d851f7 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -87,7 +87,7 @@ module Rails # config.generators.orm :my_railtie_orm # # # Add a to_prepare block which is executed once in production - # # and before which request in development + # # and before each request in development # config.to_prepare do # MyRailtie.setup! # end |