diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2012-11-03 01:56:16 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2012-11-03 01:56:16 +0530 |
commit | 3b0bb08699ce409b8213c82956dc34086dcbc8b9 (patch) | |
tree | 34398e3421fcfd86aab2b5fc757175dd2ce7664d /activerecord/lib/active_record/attribute_methods.rb | |
parent | 974467d70d337d4c60414c792e275d367143217b (diff) | |
parent | ee917493e451e552fef18367f8bcba2f36080685 (diff) | |
download | rails-3b0bb08699ce409b8213c82956dc34086dcbc8b9.tar.gz rails-3b0bb08699ce409b8213c82956dc34086dcbc8b9.tar.bz2 rails-3b0bb08699ce409b8213c82956dc34086dcbc8b9.zip |
Merge branch 'master' of github.com:lifo/docrails
Conflicts:
actionpack/lib/action_controller/metal/mime_responds.rb
activerecord/lib/active_record/attribute_methods.rb
guides/source/working_with_javascript_in_rails.md
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 101c641877..437fd00948 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -215,10 +215,10 @@ module ActiveRecord # person = Person.create!(name: 'David Heinemeier Hansson ' * 3) # # person.attribute_for_inspect(:name) - # # => '"David Heinemeier Hansson David Heinemeier Hansson D..."' + # # => "\"David Heinemeier Hansson David Heinemeier Hansson D...\"" # # person.attribute_for_inspect(:created_at) - # # => '"2009-01-12 04:48:57"' + # # => "\"2012-10-22 00:15:07\"" def attribute_for_inspect(attr_name) value = read_attribute(attr_name) @@ -234,14 +234,18 @@ module ActiveRecord # Returns +true+ if the specified +attribute+ has been set by the user or by a # database load and is neither +nil+ nor <tt>empty?</tt> (the latter only applies # to objects that respond to <tt>empty?</tt>, most notably Strings). Otherwise, +false+. + # Note that it always returns +true+ with boolean attributes. # - # class Person < ActiveRecord::Base + # class Task < ActiveRecord::Base # end # - # person = Person.new(name: '') - # person.attribute_present?(:name) # => false + # person = Task.new(title: '', is_done: false) + # person.attribute_present?(:title) # => false + # person.attribute_present?(:is_done) # => true # person.name = 'Francesco' - # person.attribute_present?(:name) # => true + # person.is_done = true + # person.attribute_present?(:title) # => true + # person.attribute_present?(:is_done) # => true def attribute_present?(attribute) value = read_attribute(attribute) !value.nil? && !(value.respond_to?(:empty?) && value.empty?) @@ -265,15 +269,16 @@ module ActiveRecord end # Returns the value of the attribute identified by <tt>attr_name</tt> after it has been typecast (for example, - # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). - # (Alias for the protected <tt>read_attribute</tt> method). It raises an <tt>ActiveModel::MissingAttributeError</tt> - # error if the identified attribute is missing. + # "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). It raises + # <tt>ActiveModel::MissingAttributeError</tt> if the identified attribute is missing. + # + # Alias for the <tt>read_attribute</tt> method. # # class Person < ActiveRecord::Base # belongs_to :organization # end # - # person = Person.new(name: 'Francesco', age: '22' + # person = Person.new(name: 'Francesco', age: '22') # person[:name] # => "Francesco" # person[:age] # => 22 # |