On Jan 18, 6:50 am, Rushen Aly <[email protected]> wrote:
> Hi everybody,
>
> I am studying Ruby on Rails Tutorial: Learn Rails by Example at
> railstutorial.org and currently i am studying chapter 7. There are
> some issues make me confused. It will be great if you help me on these
> issues.
>
> 1). We are creating virtual attributes via attr_accessor and making it
> accessible via attr_accessible. Is this statement correct? I mean if
> we create a virtual attribute via  attr_accessor cant we use it
> without declaring it with attr_accessible?

virtual attributes don't differ from normal attributes when it comes
to attr_accessible: if you've gone the whitelist approach (ie you've
used attr_accessible elsewhere), then attributes (virtual or not) are
protected from mass assignment unless you call attr_accessible on
them.

>
> 2). What is the difference between self.variable and @variable? Is it
> something like that we are using self.variable for variables not
> mentioned in attr_accesible and @variable for variables mentioned in
> attr_accesible. Is that true?
>

self.variable calls the method called variable (which may or may not
be backed by an instance variable), whereas @variable access the
instance variable of that named directly. @variable won't work for an
active record attribute, since those aren't stored in individual
instance variables (AR stores a hash of all the database attributes in
one place(

Fred

> Best regards...
> Rushen

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to