Accessing an attribute within an embedded object


#1

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


#2

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 Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#3

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 Z. 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 Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid