Forum: Ruby on Rails accessing an attribute within an embedded object

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
michael (Guest)
on 2006-02-22 19:01
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
Ezra Z. (Guest)
on 2006-02-22 21:49
(Received via mailing list)
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
michael (Guest)
on 2006-02-22 22:25
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
This topic is locked and can not be replied to.