From 890da5149df19c54124929ff8b533014b6b46e69 Mon Sep 17 00:00:00 2001 From: AvnerCohen Date: Sat, 10 Nov 2012 17:16:21 +0200 Subject: 1.9 Syntax related changes --- .../lib/active_record/nested_attributes.rb | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'activerecord/lib/active_record/nested_attributes.rb') diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index aba56c2861..4c9bd76d7c 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -50,14 +50,14 @@ module ActiveRecord # Enabling nested attributes on a one-to-one association allows you to # create the member and avatar in one go: # - # params = { :member => { :name => 'Jack', :avatar_attributes => { :icon => 'smiling' } } } + # params = { member: { name: 'Jack', avatar_attributes: { icon: 'smiling' } } } # member = Member.create(params[:member]) # member.avatar.id # => 2 # member.avatar.icon # => 'smiling' # # It also allows you to update the avatar through the member: # - # params = { :member => { :avatar_attributes => { :id => '2', :icon => 'sad' } } } + # params = { member: { avatar_attributes: { id: '2', icon: 'sad' } } } # member.update_attributes params[:member] # member.avatar.icon # => 'sad' # @@ -68,13 +68,13 @@ module ActiveRecord # # class Member < ActiveRecord::Base # has_one :avatar - # accepts_nested_attributes_for :avatar, :allow_destroy => true + # accepts_nested_attributes_for :avatar, allow_destroy: true # end # # Now, when you add the _destroy key to the attributes hash, with a # value that evaluates to +true+, you will destroy the associated model: # - # member.avatar_attributes = { :id => '2', :_destroy => '1' } + # member.avatar_attributes = { id: '2', _destroy: '1' } # member.avatar.marked_for_destruction? # => true # member.save # member.reload.avatar # => nil @@ -97,11 +97,11 @@ module ActiveRecord # be instantiated, unless the hash also contains a _destroy key # that evaluates to +true+. # - # params = { :member => { - # :name => 'joe', :posts_attributes => [ - # { :title => 'Kari, the awesome Ruby documentation browser!' }, - # { :title => 'The egalitarian assumption of the modern citizen' }, - # { :title => '', :_destroy => '1' } # this will be ignored + # params = { member: { + # name: 'joe', posts_attributes: [ + # { title: 'Kari, the awesome Ruby documentation browser!' }, + # { title: 'The egalitarian assumption of the modern citizen' }, + # { title: '', _destroy: '1' } # this will be ignored # ] # }} # @@ -116,14 +116,14 @@ module ActiveRecord # # class Member < ActiveRecord::Base # has_many :posts - # accepts_nested_attributes_for :posts, :reject_if => proc { |attributes| attributes['title'].blank? } + # accepts_nested_attributes_for :posts, reject_if: proc { |attributes| attributes['title'].blank? } # end # - # params = { :member => { - # :name => 'joe', :posts_attributes => [ - # { :title => 'Kari, the awesome Ruby documentation browser!' }, - # { :title => 'The egalitarian assumption of the modern citizen' }, - # { :title => '' } # this will be ignored because of the :reject_if proc + # params = { member: { + # name: 'joe', posts_attributes: [ + # { title: 'Kari, the awesome Ruby documentation browser!' }, + # { title: 'The egalitarian assumption of the modern citizen' }, + # { title: '' } # this will be ignored because of the :reject_if proc # ] # }} # @@ -136,12 +136,12 @@ module ActiveRecord # # class Member < ActiveRecord::Base # has_many :posts - # accepts_nested_attributes_for :posts, :reject_if => :new_record? + # accepts_nested_attributes_for :posts, reject_if: :new_record? # end # # class Member < ActiveRecord::Base # has_many :posts - # accepts_nested_attributes_for :posts, :reject_if => :reject_posts + # accepts_nested_attributes_for :posts, reject_if: :reject_posts # # def reject_posts(attributed) # attributed['title'].blank? @@ -152,10 +152,10 @@ module ActiveRecord # associated record, the matching record will be modified: # # member.attributes = { - # :name => 'Joe', - # :posts_attributes => [ - # { :id => 1, :title => '[UPDATED] An, as of yet, undisclosed awesome Ruby documentation browser!' }, - # { :id => 2, :title => '[UPDATED] other post' } + # name: 'Joe', + # posts_attributes: [ + # { id: 1, title: '[UPDATED] An, as of yet, undisclosed awesome Ruby documentation browser!' }, + # { id: 2, title: '[UPDATED] other post' } # ] # } # @@ -170,11 +170,11 @@ module ActiveRecord # # class Member < ActiveRecord::Base # has_many :posts - # accepts_nested_attributes_for :posts, :allow_destroy => true + # accepts_nested_attributes_for :posts, allow_destroy: true # end # - # params = { :member => { - # :posts_attributes => [{ :id => '2', :_destroy => '1' }] + # params = { member: { + # posts_attributes: [{ id: '2', _destroy: '1' }] # }} # # member.attributes = params[:member] @@ -197,12 +197,12 @@ module ActiveRecord # inverse_of as this example illustrates: # # class Member < ActiveRecord::Base - # has_many :posts, :inverse_of => :member + # has_many :posts, inverse_of: :member # accepts_nested_attributes_for :posts # end # # class Post < ActiveRecord::Base - # belongs_to :member, :inverse_of => :posts + # belongs_to :member, inverse_of: :posts # validates_presence_of :member # end module ClassMethods @@ -248,11 +248,11 @@ module ActiveRecord # # Examples: # # creates avatar_attributes= - # accepts_nested_attributes_for :avatar, :reject_if => proc { |attributes| attributes['name'].blank? } + # accepts_nested_attributes_for :avatar, reject_if: proc { |attributes| attributes['name'].blank? } # # creates avatar_attributes= - # accepts_nested_attributes_for :avatar, :reject_if => :all_blank + # accepts_nested_attributes_for :avatar, reject_if: :all_blank # # creates avatar_attributes= and posts_attributes= - # accepts_nested_attributes_for :avatar, :posts, :allow_destroy => true + # accepts_nested_attributes_for :avatar, :posts, allow_destroy: true def accepts_nested_attributes_for(*attr_names) options = { :allow_destroy => false, :update_only => false } options.update(attr_names.extract_options!) @@ -348,9 +348,9 @@ module ActiveRecord # For example: # # assign_nested_attributes_for_collection_association(:people, { - # '1' => { :id => '1', :name => 'Peter' }, - # '2' => { :name => 'John' }, - # '3' => { :id => '2', :_destroy => true } + # '1' => { id: '1', name: 'Peter' }, + # '2' => { name: 'John' }, + # '3' => { id: '2', _destroy: true } # }) # # Will update the name of the Person with ID 1, build a new associated @@ -360,9 +360,9 @@ module ActiveRecord # Also accepts an Array of attribute hashes: # # assign_nested_attributes_for_collection_association(:people, [ - # { :id => '1', :name => 'Peter' }, - # { :name => 'John' }, - # { :id => '2', :_destroy => true } + # { id: '1', name: 'Peter' }, + # { name: 'John' }, + # { id: '2', _destroy: true } # ]) def assign_nested_attributes_for_collection_association(association_name, attributes_collection) options = self.nested_attributes_options[association_name] -- cgit v1.2.3