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

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

Solidarity:
http://www.dailyradical.org
http://www.diarioradical.org
http://www.spboston.org

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

On Jun 5, 9:29 am, Thorsten M. [email protected]
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 :slight_smile: 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

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…

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

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

Rails T. wrote:

else

code :
Reinhart
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