# Accessing an attribute within an embedded object

**URL:** <https://www.ruby-forum.com/t/accessing-an-attribute-within-an-embedded-object/54085>\
**Category:** Rails\
**Created:** [February 22, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/accessing-an-attribute-within-an-embedded-object/54085 "2006-02-22T18:01:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [February 22, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/accessing-an-attribute-within-an-embedded-object/54085/1 "2006-02-22T18:01:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [February 22, 2006, 8:49pm UTC](https://www.ruby-forum.com/t/accessing-an-attribute-within-an-embedded-object/54085/2 "2006-02-22T20:49:00Z")

</div>

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

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![michael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4bbf92/32.png) [@michael](https://www.ruby-forum.com/u/michael)\
**Post date:** [February 22, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/accessing-an-attribute-within-an-embedded-object/54085/3 "2006-02-22T21:25:47Z")

</div>

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](http://yakimaherald.com)  
> 509-577-7732  
> removed\_email\_address@domain.invalid
