last day (16 days later) » 

7:17 PM
Hey how's it goin
I just wanna say thanks so much with your help on this
I really appreciate it
 
no worries
 
Building off of your last comment
saving the zipcodes
lemme know if I'm thinking what you are
 
sure
 
I'm thinking of creating a hash for each state that has boroughs
so for instance
:new_york => {manhattan: [10001, 10002], brooklyn: [11201,11203]}
the question would be where in the project should you store this hash
 
ya, I'd probably just put it in a "boroughs_helper"
then have a "before_save" callback in your model
before_save :verify_borough
then your verify_borough method would see if the known zipcode is in the list in your helper, is it? great let's set borough = whatever the result is
 
7:29 PM
okay lemme see if I follow you with this
def verify_borough
if self.zip_code == boroughs.any?
self.borough = # How should I assign this value?
end
end
Not sure if I should use an else case
boroughs would be the hash
containing the states with the zipcodes
I haven't tested this out just yet
wanted to see if I was along those lines
 
ya, you'll need to iterate over your hash. boroughs.select { |borough, zip| zip == self.zip }
but ya, you've got it
 
Okay I'm gonna try this now
 
7:53 PM
I revised the hash to look something like this
boroughs = {
:new_york => {manhattan: [11201,11203], brooklyn: [10001, 10002], :queens: [11001,11004]
}
}
The method you suggested seems to be working great
boroughs.select {|borough, zip| puts "#{borough} #{zip}" }
The above was just to test what was returned as far as the key, value pair
Now I'm gonna jump back into my model
 
:)
looks good!
 
how does this look?
boroughs.select do |borough, zip|
if zip == self.zip
self.borough ||= borough
end
end
not sure if I should be using ||= or maybe "else". What do you think
I basically wanna say if theres no zipcode match then don't assing this value at all and leave it blank
 
 
1 hour later…
9:22 PM
depends on what you want to save in the database
 

  last day (16 days later) »