You have to create a model called Route, should look like this:
First generate with scaffold
rails g scaffold Route start_place_id:integer end_place_id:integer distance:decimal
run migrations
Then you have to set up the relations. A Place can be a start point or an end point, because
the identification is not trivial by the relation, we have to specify the class and the foreign key to work properly.(in a simple has many association we can do has_many :routes, and belongs_to :place but that's not the case)
route.rb
class Route<ActiveRecord::Base
belongs_to :start_place, :class_name=>"Place", :foreign_key=>"start_place_id"
belongs_to :end_place, :class_name=>"Place", :foreign_key=>"end_place_id
end
In your place.rb you have to add
class Place<ActiveRecord::Base
has_many :routes_as_start, :class_name=>"Place", :foreign_key=>"start_place_id"
has_many :routes_as_end, :class_name=>"Place", :foreign_key=>"end_place_id"
end
To build a relation, you can do like this:
route = @place.routes_as_start.build
route.end_place = Place.create
route.save
This should create a route with an end place too.