Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Zeke Sikelianos

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Sample Controller method for using Nico's Contacts gem

   1  
   2    def import
   3      begin 
   4        @sites = {"gmail"  => Contacts::Gmail, "yahoo" => Contacts::Yahoo, "hotmail" => Contacts::Hotmail}
   5        @contacts = @sites[params[:from]].new(params[:login], params[:password]).contacts
   6        @users , @no_users = [], []
   7        @contacts.each do |contact|
   8            if u = User.find(:first , :conditions => "accounts.email = '#{contact[1]}'" , :include =>[:account])
   9              @users << u 
  10            else
  11              @no_users << {:name => contact[0] , :email => contact[1]}
  12            end            
  13        end
  14        respond_to do |format|
  15          format.html {render :template => 'shared/_contact_list' , :layout => false}
  16  	format.xml {render :xml => @contacts.to_xml}
  17        end	  
  18      end
  19      rescue  Contacts::AuthenticationError
  20        respond_to do |format|
  21          format.html {render :text => "Username and password do not match"}
  22  	     format.xml {head :bad_request , :bad_account_login}
  23        end
  24      end 
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS