On Jan 18, 12:16 pm, Rushen Aly <[email protected]> wrote:
> Ok then, as an example what does the code mean below
>
> def encrypt_password
>   self.encrypted_password = encrypt(self.password)
> end

Well it's calling encrypted_password= with the result of encrypting
self.password. In this particular pattern password is normally a
virtual attribute, and the encrypted version of it is stored in the
encrypted_password column

Fred

>
> Best Regards
>
> Rushen
>
> On Jan 18, 1:07 pm, Frederick Cheung <[email protected]>
> wrote:
>
>
>
> > On Jan 18, 9:34 am, Rushen Aly <[email protected]> wrote:
>
> > > Thank you for your reply,
> > > As i understand i always need to use self in spite of @ in a model
>
> > Not always, but sometimes you need to in order to resolve an ambiguity
> > eg, if you have a local variable called foo and an accessor method
> > called foo and you write
>
> > foo
>
> > then ruby needs to decide whether you wanted to call the method foo or
> > just get the local variable. self.foo or foo() tells ruby you wanted
> > to call the acessor method
>
> > if you write foo=123, ruby will always assume you wanted to set the
> > local variable foo, so you need to write self.foo =  123
>
> > Fred
>
> > > file. I have no information about mass assignment so i am searching
> > > for it...
> > > Best Regards...
> > > Rushen
>
> > > On Jan 18, 9:19 am, Frederick Cheung <[email protected]>
> > > wrote:
>
> > > > 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