Topic: Model Confusion: vs. @name


I am new to Ruby and Rails and already programmed quite a bit, but I still don't get the difference.

If I have a model User that looks like this:

class User < ActiveRecord::Base
  def status
    if self.logged_in == nil


Do I have to use self.logged_in to access the logged_in field of user1 (with ID = XY) or can I use @logged_in?

What is the difference, it is both instance variables for me, but sometimes the @xyz is not working and I have to use

When do you have to use what? What do I use to write to the table?

Thanks a lot!

Re: Model Confusion: vs. @name is a method call

It will only work if you have the following method defined:
def name

The confusion is probably that if you use the attr_reader shortcut:
attr_reader :name

it's basically doing the same as above.

If it's not there... will give a NoMethodError