aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2011-06-13 23:14:15 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2011-06-13 23:14:15 +0530
commit3b4f04ab832b00806b2de78f1947d6438dd13f59 (patch)
treea9a15d686739642b45f7af21f1ddcf6bc9752081
parent67a705f95241e447b996487e5c42f2245f83aca2 (diff)
downloadrails-3b4f04ab832b00806b2de78f1947d6438dd13f59.tar.gz
rails-3b4f04ab832b00806b2de78f1947d6438dd13f59.tar.bz2
rails-3b4f04ab832b00806b2de78f1947d6438dd13f59.zip
document the instance_accessor option for cattr_accessor
-rw-r--r--railties/guides/source/active_support_core_extensions.textile18
1 files changed, 12 insertions, 6 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 16cacc9928..f9f7f2d83c 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1036,18 +1036,24 @@ module ActionView
end
</ruby>
-we can access +field_error_proc+ in views. The generation of the writer instance method can be prevented by setting +:instance_writer+ to +false+ (not any false value, but exactly +false+):
+we can access +field_error_proc+ in views.
+
+The generation of the reader instance method can be prevented by setting +:instance_reader+ to +false+ and the generation of the writer instance method can be prevented by setting +:instance_writer+ to +false+. Generation of both methods can be prevented by setting +:instance_accessor+ to +false+. In all cases, the value must be exactly +false+ and not any false value.
<ruby>
-module ActiveRecord
- class Base
- # No pluralize_table_names= instance writer is generated.
- cattr_accessor :pluralize_table_names, :instance_writer => false
+module A
+ class B
+ # No first_name instance reader is generated.
+ cattr_accessor :first_name, :instance_reader => false
+ # No last_name= instance writer is generated.
+ cattr_accessor :last_name, :instance_writer => false
+ # No surname instance reader or surname= writer is generated.
+ cattr_accessor :surname, :instance_accessor => false
end
end
</ruby>
-A model may find that option useful as a way to prevent mass-assignment from setting the attribute.
+A model may find it useful to set +:instance_accessor+ to +false+ as a way to prevent mass-assignment from setting the attribute.
NOTE: Defined in +active_support/core_ext/class/attribute_accessors.rb+.