# Accessing object attributes

**URL:** <https://www.ruby-forum.com/t/accessing-object-attributes/185693>\
**Category:** Rails\
**Created:** [March 24, 2010, 6:32pm UTC](https://www.ruby-forum.com/t/accessing-object-attributes/185693 "2010-03-24T18:32:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 24, 2010, 6:32pm UTC](https://www.ruby-forum.com/t/accessing-object-attributes/185693/1 "2010-03-24T18:32:48Z")

</div>

I have an hash of display names and their corresponding object  
attribute names called @columns.  
As I iterate through @columns, what is the syntax for accessing the  
attribute of the object using c? I get an error on the 4th line.

```
    <% for c in @columns["object_"removed_email_address@domain.invalid] do %>
       <tr>
       <td class="name"><%=c.first%></td>
       <td><%= @object.c.second %></td>
       </tr>

    <% end %>
```

---

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 24, 2010, 7:48pm UTC](https://www.ruby-forum.com/t/accessing-object-attributes/185693/2 "2010-03-24T19:48:53Z")

</div>

On Wed, Mar 24, 2010 at 10:31 AM, ES [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have an hash of display names and their corresponding object  
> attribute names called @columns.  
> As I iterate through @columns, what is the syntax for accessing the  
> attribute of the object using c? I get an error on the 4th line.

> ```
> <% for c in @columns["object_"removed_email_address@domain.invalid] do %>
> <tr>
> <td class="name"><%=c.first%></td>
> <td><%= @object.c.second %></td>
> </tr>
> <% end %>
> 
> ```

It’s really hard for me to tell what you’re trying to do here. How about  
we simplify and take it from there?

\<% @columns.each do |key, value| %\>  
\<%= key %\> = \<% value %\>  
\<% end %\>

Now, what is “@object” and how does it relate to the contents of  
either ‘key’ or ‘value’?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 25, 2010, 8:52am UTC](https://www.ruby-forum.com/t/accessing-object-attributes/185693/3 "2010-03-25T08:52:34Z")

</div>

Thanks for your reply!  
I have figured it out…

it should be

```
       <td><%= @echantillon[c.second] %></td>

```

On Mar 24, 7:47 pm, Hassan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
