Prashant Tiwari
2006-May-12 06:36 UTC
[Rails] Problem regarding accessing attributes from object...
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
--
Posted via http://www.ruby-forum.com/.
Ryan Prins
2006-May-12 07:11 UTC
[Rails] Problem regarding accessing attributes from object...
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. On 5/11/06, Prashant Tiwari <tiwari_p_k@yahoo.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ryan Prins rprins@gmail.com http://www.lazyi.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060512/923b2738/attachment.html
Prashant Tiwari
2006-May-12 08:35 UTC
[Rails] Re: Problem regarding accessing attributes from object...
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 Prins 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.
--
Posted via http://www.ruby-forum.com/.