# Rflickr search tool display total returned photos

**URL:** <https://www.ruby-forum.com/t/rflickr-search-tool-display-total-returned-photos/118901>\
**Category:** Rails\
**Created:** [November 1, 2007, 7:55am UTC](https://www.ruby-forum.com/t/rflickr-search-tool-display-total-returned-photos/118901 "2007-11-01T07:55:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocketgofaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@rocketgofaster](https://www.ruby-forum.com/u/rocketgofaster)\
**Post date:** [November 1, 2007, 7:55am UTC](https://www.ruby-forum.com/t/rflickr-search-tool-display-total-returned-photos/118901/1 "2007-11-01T07:55:26Z")

</div>

I’m attempting to display the total images returned in a search using  
the rflickr plugin. Let me know if i should provide more info, i think  
i’ve included the relevant code.

I’m a total newbie and could use a hand.

Thanks in advance.

# in my flickr/index.html

\<%= form\_remote\_tag :url =\> {:action =\> ‘search’}, :update =\> ‘photos’,  
:complete =\> visual\_effect(:blind\_down, ‘photos’),  
:before =\> %(Element.show(‘spinner’)),  
:success =\> %(Element.hide(‘spinner’)) %\>

```
<%= image_tag 'spinner.gif', :id => 'spinner', :style => 'display:

```

none’ %\>  
  
Tags:  
\<%= text\_field\_tag ‘tags’ %\>

```
    <%= submit_tag 'Find' %>
</fieldset>

<div id="photos" style="display: none"></div>

```

\<%= end\_form\_tag %\>

# in my flickr.controller.rb

class FlickrController \< ApplicationController  
def search  
flickr =  
Flickr.new(’/www.rocketgofaster.com/development/rocketgofaster\_machine/config/flickr.cache’,‘32dd6bece5332b32d1d4f8ab601290ab’,‘800c7f9d6e0012a8’)  
render :partial =\> “photo”, :collection =\>  
flickr.photos.search(nil,params[:tags],nil,nil,nil,nil,nil,nil,nil,nil,‘100’)  
end

def search\_total

end

end

# in rflickr plugin photos.rb

def search(user=nil,tags=nil,tag\_mode=nil,text=nil,min\_upload\_date=nil,  
max\_upload\_date=nil,min\_taken\_date=nil,max\_taken\_date=nil,  
license=nil,extras=nil,per\_page=nil,page=nil,sort=nil)

user = user.nsid if user.respond\_to?(:nsid)  
tags = tags.join(’,’) if tags.class == Array  
min\_upload\_date = min\_upload\_date.to\_i if  
min\_upload\_date.class == Time  
max\_upload\_date = max\_upload\_date.to\_i if  
max\_upload\_date.class == Time  
min\_taken\_date = @flickr.mysql\_datetime(min\_taken\_date) if  
min\_taken\_date.class == Time  
max\_taken\_date = @flickr.mysql\_datetime(max\_taken\_date) if  
max\_taken\_date.class == Time  
license = license.id if license.class == Flickr::License  
extras = extras.join(’,’) if extras.class == Array

args = {}  
args[‘user\_id’] = user if user  
args[‘tags’] = tags if tags  
args[‘tag\_mode’] = tag\_mode if tag\_mode  
args[‘text’] = text if text  
args[‘min\_upload\_date’] = min\_upload\_date if min\_upload\_date  
args[‘max\_upload\_date’] = max\_upload\_date if max\_upload\_date  
args[‘min\_taken\_date’] = min\_taken\_date if min\_taken\_date  
args[‘max\_taken\_date’] = max\_taken\_date if max\_taken\_date  
args[‘license’] = license if license  
args[‘extras’] = extras if extras  
args[‘per\_page’] = per\_page if per\_page  
args[‘page’] = page if page  
args[‘sort’] = sort if sort

res = @flickr.call\_method(‘flickr.photos.search’,args)  
return Flickr::PhotoList.from\_xml(res,@flickr)  
end

# in rflickr plugin

class Flickr::PhotoList \< Array  
attr\_reader :page,:pages,:perpage,:total

def initialize(page,pages,perpage,total)  
@page = page  
@pages = pages  
@perpage = perpage  
@total = total  
end

def self.from\_xml(xml,flickr=self)  
att = xml.root.attributes  
list = Flickr::PhotoList.new(att[‘page’].to\_i,att[‘pages’].to\_i,  
att[‘perpage’].to\_i,att[‘total’].to\_i)  
xml.elements[’/photos’].each\_element do |e|  
list \<\< Flickr::Photo.from\_xml(e,flickr)  
end  
return list  
end  
end

---

<div class="post-metadata">

**Author:** ![rocketgofaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@rocketgofaster](https://www.ruby-forum.com/u/rocketgofaster)\
**Post date:** [November 2, 2007, 12:26am UTC](https://www.ruby-forum.com/t/rflickr-search-tool-display-total-returned-photos/118901/2 "2007-11-02T00:26:13Z")

</div>

Hi, im not really sure I understand what you are looking for… its been  
a  
while since I worked with rflickr.

You seem to be passing a collection of objects to the view in your first  
action - do you want the number of elements in that collection?

if so

flickr.photos.search  
(nil,params[:tags],nil,nil,nil,nil,nil,nil,nil,nil,‘100’).size

if you are struggling to display this in the view I would do this.

in your view:

then in your search action

def search  
your code up to before the render  
render :update do |page|  
page.replace\_html “photos”, render :partial =\> “photo”, :collection  
=\>  
#{that long line with the nils}  
page.replace\_html “image\_count”, “#{(that long line with the  
nils).size}  
photos were found.”  
end  
end

this will add the count in the same action and negate the need for a  
seperate action to do that.

am I missing something?

regards  
ivor

---

<div class="post-metadata">

**Author:** ![rocketgofaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@rocketgofaster](https://www.ruby-forum.com/u/rocketgofaster)\
**Post date:** [November 2, 2007, 1:15am UTC](https://www.ruby-forum.com/t/rflickr-search-tool-display-total-returned-photos/118901/3 "2007-11-02T01:15:30Z")

</div>

Actually, Im looking to get the total number of images provided in the  
xml response to the image search.

\*\*the total parsed in the photolist below, or atleast i think so?

```
list = Flickr::PhotoList.new(att['page'].to_i,att['pages'].to_i,
  att['perpage'].to_i,att['total'].to_i)

```

\*\*from the flickr api, the total below

Example Response

This method returns the standard photo list xml:

thanks in advance  
rocket
