Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 58 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. ## in model.rb
  2.  
  3. def new_model_method(params)
  4.   if params[:zip].present? && !params[:address].present?
  5.     begin
  6.       @people = Person.zip_search(params)
  7.       if @people.count > 1
  8.         @notice = "More than one district for your zip code. Please enter your full address."
  9.         @show_address_field = true
  10.       end
  11.       rescue Exceptions::DistrictLookupError
  12.         @error = "No congressional district was found for the zip code given."
  13.         @people = Person.all.paginate
  14.       end
  15.   elsif params[:address].present?
  16.     begin
  17.       @people = Person.address_search(params).paginate
  18.       rescue Exceptions::GeocodeError
  19.         @people = Person.all.paginate
  20.         @error = "Error looking up your congressional district: \"#{$!}\""
  21.       end
  22.   else
  23.     @people = Person.people_search(params)
  24.   end
  25.   return [@people, @notice, @error, @show_address_field]
  26. end
  27.  
  28. ## in controller
  29.  
  30. def index
  31.  
  32.   @people, flash[:notice], flash[:error], @show_address_field = Person.new_model_method(params)
  33.  
  34.   ....
  35. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top