Forum: Ruby on Rails Trader/Service/Location model pitstop

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
64caa824bc3d2950720f338994790adc?d=identicon&s=25 Jonlee P. (jayel)
on 2014-06-25 19:23
(Received via mailing list)
I have a feeling I am gonna get my ass kicked here, but this is my first
attempt at creating real life model logic

I have 3 models:

  Trader -

  Service -

  Location -

and my DB Schema is:

This is all I have at the moment and it does exactly what I want it to
 I will plan on my controller and views later but I want to pause and
review on my work and could use some help as I am unsure if I am
callbacks especially in the Service model and what I could do otherwise.

A quick overview of the plan is:

A Trader has and belongs to many Locations and vice-versa, and a Trader
many Services each of which have a range.  This range is the distance a
trader may travel to provide the service from their central post_code
a builder might travel 20 miles to build a porch but would travel 50
for a customer to build a full house extension.  Therefore the Locations
for a Trader all hinge on the maximum range of their Services.

The Locations table is populated with UK postcode data with Lat/Lon
coordinates and all distances and ranges are calculated using the

The plan is when a User visits the website they enter their post code,
firstly all Traders in the Location will be identified.  Then When the
clicks on a specific Trader, the Trader=>'services_in' function will be
called to only show the services that the trader provides within their

I hope that makes sense and you have a little time to peruse the models,
could really do with having a discussion on what I have created so far
see how smelly my code is.  As I say I have never done anything to this
level before.

much regards

Philippe Guégan (Guest)
on 2014-06-25 20:45
(Received via mailing list)
Hi Jonlee,

At first sight, all I have to say is that your Location model could be
greatly simplified with the use of the geocoder
<> gem. It provides great
functionalities when dealing with GPS coordinates, especially computing
distances or searching within a given area.

Hope this helps :)


Le mercredi 25 juin 2014 19:09:21 UTC+2, Jonlee Peakman a écrit :
64caa824bc3d2950720f338994790adc?d=identicon&s=25 Jonlee P. (jayel)
on 2014-06-25 20:58
(Received via mailing list)
Thanks, I have seen a bit about that, does it work without an external
API like Google etc?
This topic is locked and can not be replied to.