[Rails] Re: Virtual attributes in Rails
sree ilapakurthy wrote in post #1108220:
> What do you knew about virtual attriburtes in rails ? Generally we can
> get
> idea about attr_accessible and attr_accessor
>
> so what these two can do . i found the difference between these two from
> this blog. Very useful plz check it
>
http://mywayonrails.wordpress.com/2013/04/01/virtual-attributes-in-rails/#more-174.<http://mywayonrails.wordpress.com/2013/04/01/virtual-attributes-in-rails/>
The first thing you should know is that attar_accessible will be removed
from Rails 4 to be replaced by strong parameters.
See here for more:
http://weblog.rubyonrails.org/2012/3/21/strong-parameters/
The attar_accessor is really nothing more than a declarative statement
for specifying getters and setters for instance variable (which is
really all that virtual attributes are). In anything other than
ActiveRecord models "virtual attributes" are called "instance
variables." Sometimes these are also called "transient variables"
because they are attributes that are to be excluded from persistence
either in a serialized format or persistent storage (database). Some
languages have specific syntax for transient variables although AFAIK
Ruby does not.
Example:
attr_accessible :name
is essentially equivalent to
def name
@name
end
def name=(name)
@name = name
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home