Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## in model.rb
- def new_model_method(params)
- if params[:zip].present? && !params[:address].present?
- begin
- @people = Person.zip_search(params)
- if @people.count > 1
- @notice = "More than one district for your zip code. Please enter your full address."
- @show_address_field = true
- end
- rescue Exceptions::DistrictLookupError
- @error = "No congressional district was found for the zip code given."
- @people = Person.all.paginate
- end
- elsif params[:address].present?
- begin
- @people = Person.address_search(params).paginate
- rescue Exceptions::GeocodeError
- @people = Person.all.paginate
- @error = "Error looking up your congressional district: \"#{$!}\""
- end
- else
- @people = Person.people_search(params)
- end
- return [@people, @notice, @error, @show_address_field]
- end
- ## in controller
- def index
- @people, flash[:notice], flash[:error], @show_address_field = Person.new_model_method(params)
- ....
- end
Add Comment
Please, Sign In to add comment