Skip to content

Instantly share code, notes, and snippets.

@mrsweaters
Last active October 19, 2015 15:53
Show Gist options
  • Select an option

  • Save mrsweaters/77035b2963f14a562295 to your computer and use it in GitHub Desktop.

Select an option

Save mrsweaters/77035b2963f14a562295 to your computer and use it in GitHub Desktop.
Engineering 1
<html>
<body>
<% @warehouses.each do |warehouse| %>
<h2><%= warehouse %></h2>
<ul class="trucks">
<% warehouse.trucks.each do |truck| %>
<li>ID: <%= truck.id %><br>Miles: <%= truck.miles %></li>
<% end %>
<% end %>
</body>
</html>
# Truck { id, name, miles }
class Truck < ActiveRecord::Base
belongs_to :warehouse
end
# Warehouse { id, name, description, location }
class Warehouse < ActiveRecord::Base
has_many :trucks
end
class WarehouseController < ApplicationController
def index
@warehouses = Warehouse.order('created_at asc')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment