# Problem regarding accessing attributes from object

**URL:** <https://www.ruby-forum.com/t/problem-regarding-accessing-attributes-from-object/60335>\
**Category:** Rails\
**Created:** [May 12, 2006, 8:35am UTC](https://www.ruby-forum.com/t/problem-regarding-accessing-attributes-from-object/60335 "2006-05-12T08:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 12, 2006, 8:35am UTC](https://www.ruby-forum.com/t/problem-regarding-accessing-attributes-from-object/60335/1 "2006-05-12T08:35:41Z")

</div>

## Hi, I have an object (@cnt). Now when I am calling “@cnt.inspect” on object it gives me output as follows:- ----output---- [#“3”}\>]

# Now in aboove output the number between double quotes (3) which is of my interest & I want to display it. How to do that? Actually this is my method:-

class Tagging \< ActiveRecord::Base

# def self.find\_count\_of\_tag(tag\_name) find\_by\_sql(["SELECT count(\*) as cntnew FROM taggings " + “WHERE taggings.tag\_id = (SELECT tags.id from tags where tags.name= ‘food’)”]) end end

Now this is code in my view:-  
@cnt=@cnt=Tagging.find\_count\_of\_tag(‘food’)

Now how to get the value of count which is returned by method with SQL  
??

PLease help me.  
Thanx in advance.  
Prash

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 12, 2006, 9:12am UTC](https://www.ruby-forum.com/t/problem-regarding-accessing-attributes-from-object/60335/2 "2006-05-12T09:12:56Z")

</div>

Now that you have @cnt, try @cnt.cntnew. Since that is what you are  
calling  
the attribue as you defined in your AS part of your SQL query.

---

<div class="post-metadata">

**Author:** ![tiwaripk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7ab992/32.png) [@tiwaripk](https://www.ruby-forum.com/u/tiwaripk)\
**Post date:** [May 12, 2006, 10:35am UTC](https://www.ruby-forum.com/t/problem-regarding-accessing-attributes-from-object/60335/3 "2006-05-12T10:35:42Z")

</div>

# Hi, I tried with @cnt.cntnew bjt getting error as:-

# undefined method `cntnew’ for [#\<Tagging:0x359bbc8 @attributes={“cntnew”=\>“3”}\>]:Array

Why I am getting this error n how 2 correct it?  
Thanx,  
Prash

Ryan P. wrote:

> Now that you have @cnt, try @cnt.cntnew. Since that is what you are  
> calling  
> the attribue as you defined in your AS part of your SQL query.
