Skip to content

Instantly share code, notes, and snippets.

@scottjacobsen
Forked from techbrownbags/rails4_has_one
Last active December 23, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottjacobsen/6629675 to your computer and use it in GitHub Desktop.
Save scottjacobsen/6629675 to your computer and use it in GitHub Desktop.
#assuming schema is
# table turbines
# id integer
# turbine_type_id integer
# table turbine_types
# id integer
# name string
class Turbine < ActiveRecord::Base
belongs_to :turbine_type # fk is in turbines, so belongs_to belongs here.
end
class TurbineType < ActiveRecord::Base
has_many :turbines
end
show.html.erb
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @turbine.name %>
</p>
<p>
<strong>Type:</strong>
<%= @turbine.turbine_type.name %>
</p>
<%= link_to 'Edit', edit_turbine_path(@turbine) %> |
<%= link_to 'Back', turbines_path %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment