[Hobo Users] Re-filtering a collection

18 views
Skip to first unread message

Scorpio

unread,
Mar 9, 2012, 9:44:30 AM3/9/12
to Hobo Users
I'm almost done fighting with my logging model and i've got an IP
details page where a collection if filtered as follows

def ip
self.this = IpLog.where(:logged_ip => params[:ip])
end

I've created a custom collection that shows the dates actions and all
the stuff I need just the way I need it but above that collection I'd
like to have something like a subsection "Users that have logged in
with this ip" (not spot on English but you get what I mean hopefully)

Idealy I'd like there to be 4 columns in that subsection

Name | Last Login| First Login | Number of times logged in

technically the base collection already has that info as it has every
action from that ip so I just kinda need to filter this base
collection and count it. I know how to do a rails count but filtering
in a collection tag _ABOVE_the base collection while keeping the base
intact is a problem. So is counting with Hobo (Man... that sounds like
a kids book "Counting with Hobo" nvm- off-topic ). I'm concerned about
filtering so that it keeps the good data below the secondary
collection as it is.

Bob Sleys

unread,
Mar 9, 2012, 9:56:56 AM3/9/12
to hobo...@googlegroups.com
Have you though about using a scope and sql to do all this for you?  I do something similar but not quite as complex but I would thing you could use sql to aggregate the numbers you need.

Here is where I find all materials that are loaded for a building.  This is in the materials model and I pass to it in controller where a need a collection of all building materials the building I'm interested in ie @building_materials = Material.for_building(@material.building) 

  scope :for_building, lambda { |b|
    where("building_id = ?", b.id).
        order(:name)
  }

Bob

Scorpio

unread,
Mar 9, 2012, 10:20:12 AM3/9/12
to Hobo Users
Hmmm the scope may indeed solve the collection problem but how do I
integrate it with a page that already has another collection?

Bob Sleys

unread,
Mar 9, 2012, 10:39:37 AM3/9/12
to hobo...@googlegroups.com
I belive you can do a collection inside another collection.

IE something like

<collection:ips>
   <view:users>
      <collection/>
   </view:users>
</collection:ips>
Reply all
Reply to author
Forward
0 new messages