ruby on rails - How do I use the zip code gem? -


(very new stack, please gentle.)

i'm wondering how incorporate zip code function app. app forum of sort-of reddit-like quality. stands, users can post, comment, crud, upload pictures, sort of thing.

the goal somehow include person's zip code on posts. trouble is, i've no idea how that. downloaded zip-codes gem, i've no idea how implement it.

is there idea how can on this?

thanks in advance.

the zipcodes gem has city/state data given zipcode. if want user's location ip you'll want geocoder adds location method request hash:

def create   @post = post.new(post_params)   @post.zipcode = request.location.postal_code    if @post.save     # ...   else     # ...   end end 

for lighter weight solution, check out freegeoip.net. can send request url https://freegeoip.net/json/70.123.123.13 , grab zipcode response.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -