Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between *, self.* and @* when referencing associations/attributes in Ruby/Rails Models/Controllers

Tags:

Assuming a Rails Model with persistent / non-persistent attributes, what is the best practice regarding referencing them? If you look at code publicly available, different patterns are used.

For instance, if you have an association from one model to another. What is the difference between using self.association_name and @association_name?. What is the preferable way?

Same as with non-persistent attributes defined with attr_accessor :attr in Models. You can reference them with both approaches, self.attr and @attr. What is the preferable way?