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.. <table> <tr>     <th colspan="4">My Friend's JID's </th> </tr>

<% @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" %></td>                 <td><%= amigo.jid %></td>          <% end %>         </tr>      <% end %> </table>

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

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" %></td>                 <td><%= amigo.jid %></td>          <% end %>         </tr>      <% end %> </table>

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

Frederick Cheung wrote:

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

Rails Terrorist wrote:

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   

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

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