From: Lyle Johnson Date: 2002-09-20T14:20:31+09:00 Subject: Re: Attribute Access Problems Matthew, Graeme wrote: > I'm just not getting this! Don't Panic! > What am I doing wrong here, this is taking way to long :-( > > c:/dev/cgi-bin/Project.rb:80:in `DisplayProject': undefined method > `projectName' for # (NameError) OK, I know you can read, but just to clarify: this error message is telling you that you're trying to call an instance method named "projectName" for the "Project" class, but there is no instance method by that name. > I'm now using instance variables > > def projectName=(val) > @projectName = val if val > return @projectName > end This looks fine, but keep in mind that "projectName=()" (a "setter" method) and "projectName()" (a "getter" method) are *two* different method names... > but it's failing here in my document: > > Name value="#{self.projectName}"> Although we can't see all of the code for your "Project" class, I'm guessing that you didn't define a "projectName" accessor method to complement the "projectName=" method. A quick way to do this (since you also have a "@projectName" instance variable) is to use the attr_reader method: class Project attr_reader :projectName end A more verbose (but otherwise equivalent) way to do it is to explicitly code-up the method: class Project def projectName @projectName end end If you don't already have "Programming Ruby" (a.k.a. the "Pickaxe" book) I'd recommend you pick up a copy. It's also available for free online. The second chapter: http://www.rubycentral.com/book/tut_classes.html has a section entitled "Objects and Attributes" that does a very nice job of explaining what's going on. Hope this helps, Lyle