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'' %>
<fieldset>
<label for="tags">Tags:</label>
<%= 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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:
<div id="image_count"></div>
<div id="photos" style="display:none;"></div>
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
On 11/1/07, Rocket Gofaster
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> 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'' %>
> <fieldset>
> <label for="tags">Tags:</label>
> <%= 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
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Rocket Gofaster
2007-Nov-02 00:15 UTC
Re: rflickr search tool display total returned photos
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:
<photos page="2" pages="89" perpage="10"
total="881">
<photo id="2636" owner="47058503995@N01"
secret="a123456" server="2" title="test_04"
ispublic="1" isfriend="0" isfamily="0" />
<photo id="2635" owner="47058503995@N01"
secret="b123456" server="2" title="test_03"
ispublic="0" isfriend="1" isfamily="1" />
<photo id="2633" owner="47058503995@N01"
secret="c123456" server="2" title="test_01"
ispublic="1" isfriend="0" isfamily="0" />
<photo id="2610" owner="12037949754@N01"
secret="d123456" server="2" title="00_tall"
ispublic="1" isfriend="0" isfamily="0" />
</photos>
thanks in advance
rocket
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---