# Whats wrong here? I get the same result of each item

**URL:** <https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584>\
**Category:** Rails\
**Created:** [June 5, 2008, 7:20am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584 "2008-06-05T07:20:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2008, 7:20am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/1 "2008-06-05T07:20:52Z")

</div>

I get the same result off.png for each amigo.jid that I sent to  
isonline. were it should be on.png or off.png

this is in the view…

\<% @amigos.in\_groups\_of(2, false) do |grupo| %\>

```
    <tr class="<%= cycle('odd', 'even') -%>">
    <% grupo.each do |amigo| %>
            <td><%= image_tag isonline(amigo.jid), :alt => "Status"

```

%\>

  
\<% end %\>  
  
\<% end %\>

| My Friend's JID's |
| --- |
| \<%= amigo.jid %\> |

this is in my helper:

def isonline(amigo)  
@isonline = nil  
@online = Status.find(:all, :select =\> “status”,  
:conditions =\> { :“collection-owner” =\> “#{amigo}” })

```
            if @online == "online"
                    @isonline = "on.png"
            else
                    @isonline = "off.png"
            end

    end

```

–  
A Spectre is haunting multinational capitalism–the spectre of free  
information.  
All the powers of ``globalism’’ have entered into an unholy alliance to  
exorcize this spectre:  
Microsoft and Disney, the World Trade Organization, the United States  
Congress and the European Commission.  
Eben Moglen from the FSF.  
[http://emoglen.law.columbia.edu/publications/dcm.html](http://emoglen.law.columbia.edu/publications/dcm.html)

Solidarity:  
[http://www.dailyradical.org](http://www.dailyradical.org)  
[http://www.diarioradical.org](http://www.diarioradical.org)  
[http://www.spboston.org](http://www.spboston.org)

> **[MESSIPOKER - Situs Judi Slot Online Dan Toto 4D Togel Terbaru](https://binaryfreedom.info/)**
>
> MESSIPOKER ialah situs judi slot online terbaik dan toto 4D online terpercaya no 1 di Indonesia yang siap memberikan pelayanan maksimal kepada anda.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2008, 10:29am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/2 "2008-06-05T10:29:51Z")

</div>

This line:

> @online = Status.find(:all, :select =\> “status”,  
> :conditions =\> { :“collection-owner” =\> “#{amigo}” })

will retrieve the status col from status. But @online is still  
an ActiveRecord object.

So your condition

> if @online == “online”

should be

if @online.status == "online

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2008, 11:01am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/3 "2008-06-05T11:01:41Z")

</div>

On Jun 5, 9:29 am, Thorsten M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> This line:
> 
> > @online = Status.find(:all, :select =\> “status”,  
> > :conditions =\> { :“collection-owner” =\> “#{amigo}” })
> 
> will retrieve the status col from status. But @online is still  
> an ActiveRecord object.

Not quite 🙂 it’s an array. find :first is probably what is wanted.  
You also don’t need the quotes around amigo - :“collection-owner” =\>  
amigo would work just as well

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2008, 2:27am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/4 "2008-06-06T02:27:19Z")

</div>

Hi guys, thanks, I got it to work on the console…  
but when I do it from the app is not working…  
it says I am sending a NIL, when I hard code a username then it works…  
so it has to be the way I sent the variable from the view.  
\<% @amigos.in\_groups\_of(2, false) do |grupo| %\>

```
    <tr class="<%= cycle('odd', 'even') -%>">
    <% grupo.each do |amigo| %>
            <td><%= image_tag isonline(amigo.jid), :alt => "Status"

```

%\>

\<%= amigo.jid %\>  
\<% end %\>  
  
\<% end %\>

whats wrong with isonline(amigo.jid) ???  
amigo.jid works just fine in the next line…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2008, 5:05am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/5 "2008-06-06T05:05:22Z")

</div>

your amigo.jid is fine. but your helper isnt fine.

def isonline(amigo)  
@isonline = nil  
@online = Status.find\_by\_collection\_owner(amigo, :select =\>  
“status”)

```
if @online.status == "online"
   @isonline = "on.png"
else
   @isonline = "off.png"
end

```

end

please remember that you use find :all, it means that the result would  
be array, when you need to see the result of each array you should  
describe index key like @online[0] or @online[1] like that. Look your  
code :

> @online = Status.find(:all, :select =\> “status”,  
> :conditions =\> { :“collection-owner” =\> “#{amigo}” })

the result would be @online[0].status, please understand carefully find  
:all is diferent with find(id) ← it will show you hashing.

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2008, 8:35am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/6 "2008-06-06T08:35:31Z")

</div>

I tested your script like below and it works :

module RosteritemsHelper

def isonline(amigo)  
@online = Status.find(:first, :select =\> “status”, :conditions =\> {  
:“collection-owner” =\> amigo })

if @online != nil && @online.status == “online”  
@isonline = “on.png”  
else  
@isonline = “off.png”  
end

end

Remember to save both of your image in /public/images. I tested script  
above and really working fine.

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2008, 6:20am UTC](https://www.ruby-forum.com/t/whats-wrong-here-i-get-the-same-result-of-each-item/139584/7 "2008-06-06T06:20:53Z")

</div>

Rails T. wrote:

> ```
> else
> 
> ```
> 
> code :  
> Reinhart  
> [http://teapoci.blogspot.com](http://teapoci.blogspot.com)

Hi, yes I know I did changed my helper… this is what I have now… I  
also added just now to check for nil in case some records have  
problems…

module RosteritemsHelper  
def isonline(amigo)  
@online = Status.find(:first, :select =\> “status”,  
:conditions =\> { :“collection-owner” =\> amigo })  
unless @online.nil?  
if @online.status == “online”  
@isonline = “on.png”  
else  
@isonline = “off.png”  
end  
end  
end  
end
