On Thu, May 5, 2011 at 3:34 AM, S Ahmed <sahmed1...@gmail.com> wrote:

> I'm a little confused when I should be using 'self' in my model.
>
> I had code like:
>
> class User < ActiveRecord::Base
>
> before_save   :do_something
>
>
> def do_something
>
>   self.user_bio_text = ....
>   ..
>   self.user_bio_text
> end
>
>
> end
>
>
>
> If I removed 'self', it didn't seem to set the model's attribute at all (it
> would return nil).
>
>
when assigning values to attributes of an instance object, you need to use
self, ie self.attribute = something.
if you're only getting the value of that attribute, no need to add self.


> I can't recall exaclty where this happenend in my code, but I remember that
> I was trying to get the a model's attribute and it didn't work when I used
> 'self.some_attribute'.
>
>
> So I'm confused, when do I use 'self' and when't don't I?
>
> --
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>



-- 
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to