[Rails] Re: why do I have to refer to my attr_accessible as self.varname?
7stud -- wrote in post #1089991:
>
> And here is how to correct the problem:
>
> class Dog
> def title=(val)
> @title = val.capitalize
> end
>
> def do_stuff
> self.title = "mr."
> title + " Dog"
> end
> end
>
> puts Dog.new.do_stuff
>
>
That should be:
class Dog
def title=(val)
@title = val.capitalize
end
#MISSING getter **********
def title
@title
end
def do_stuff
self.title = "mr."
title + " Dog"
end
end
puts Dog.new.do_stuff
--output:--
Mr. Dog
--
Posted via http://www.ruby-forum.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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home