When I dump an instance variable to the web browser using object.inspect I get the following: This: <%= debug archive.inspect %> Yields this: #<RapturePost:0x2aaaacada118 @attributes={\"date_created\"=>\"2006-02\"}>" How do I access that date created value? Neither of the following work. The don''t give me the actual date value, only nil or blank. archive.date_created archive.attributes.date_created Any suggestions? michael -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Feb-22 19:44 UTC
[Rails] accessing an attribute within an embedded object
On Feb 22, 2006, at 9:01 AM, michael wrote:> When I dump an instance variable to the web browser using > object.inspect > I get the following: > > This: > <%= debug archive.inspect %> > > Yields this: > #<RapturePost:0x2aaaacada118 > @attributes={\"date_created\"=>\"2006-02\"}>" > > How do I access that date created value? > > Neither of the following work. The don''t give me the actual date > value, > only nil or blank. > archive.date_created > archive.attributes.date_created > > Any suggestions? > > > michael > >Michael- You use debug without inspect. Thats where you are getting your errors from. try it l;ike this instead: <%= debug archive %> L:eave off the inspect. Also it looks like your problem might arrise from you using local var instead of an @instance var but that might not be the case. Cheers- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra@yakima-herald.com
michael
2006-Feb-22 20:25 UTC
[Rails] Re: accessing an attribute within an embedded object
Actually, my error isn''t in the debug. I''m using debug is simply output my data. My error is that I cannot seem to access the date_created attribute. Basically, I have the following: @components which has an attribute called archives that i access through: @components.archives @components.archives is an array of objects (database rows) that I am trying to access by saying: <% for archive in @components.archives -%> <%= debug(archive.instance) %> <% end -%> If I use debug(archive) without using instance, I get the following --- !ruby/object:RapturePost attributes: date_created: 2006-02 But I can''t seem to access that date_created attribute through the archive variable with any of the following: archive.date_created archive.attributes.date_created archive.RapturePost.date_created Any ideas? michael Ezra Zygmuntowicz wrote:> On Feb 22, 2006, at 9:01 AM, michael wrote: > >> >> >> michael >> >> > > > Michael- > > You use debug without inspect. Thats where you are getting your > errors from. try it l;ike this instead: > > <%= debug archive %> > > L:eave off the inspect. Also it looks like your problem might arrise > from you using local var instead of an @instance var but that might > not be the case. > > Cheers- > > -Ezra Zygmuntowicz > Yakima Herald-Republic > WebMaster > http://yakimaherald.com > 509-577-7732 > ezra@yakima-herald.com-- Posted via http://www.ruby-forum.com/.