Search code examples
ruby-on-railsrubydevisegmaps4railsrails-geocoder

use geocoder gem to store address of one model search with address of the other model


I have 2 models one for customer and one for vendor, I'm trying do make a site that when customer sign in, they can search using their ip address and search for near by location, the result will be some vendor with nearby address. So far, I plan to use geocoder and gmap4rails gem. I'm still not sure how I would store the vendors address using geocoder so that when the customer search, the correct result will be presented. Can some one give suggestion on how to design this feature?


Solution

  • Since you're just looking for a "design" and not code, I can just outline the broad steps:

    ip form submitted =>
    lookup geodata for local businesses =>
    store geodata in "vendor" model =>

    The only non-standard rails part of this is the geo-lookup.

    There are multiple ways to do this, most certainly using some external API. I don't think the geocoder or gmap4rails gems have this functionality.

    While you're probably using gmap4rails for your view layer, I'm not sure you'll need the geocoder gem if you're using a different service to perform the vendors lookup. This external service might accomplish the same thing.

    As for which external service to use: I'd look at Yelp or one of Google's APIs.


    In response to your comment:

    When a user logs in, you'll probably want to set a session cookie for them.

    There is no reason to have the ip form "belong to" any user. When the form is submitted, you'd be able to look up the current signed in user from the controller action which is hit when the form is submitted.

    If you store vendor data in your database, you can then present the data in the view.

    If these concepts are new to you, I'd recommend going through a detailed tutorial of Rails.