Answers for Part D Sample Final B

1. rails g scaffold DiamondBroker name:string phone:string 
      address:text license_no:string
   rails g scaffold CutDiamond carats:float color:string

2. rails g migration AddDiamondBrokerIdToCutDiamond diamond_broker_id:integer

3a. In app/models/diamond_broker.rb:
       has_many :cut_diamonds
    In app/models/cut_diamonds.rb: 
       belongs_to :diamond_broker

3b. In app/models/cut_diamonds.rb add:
       validates :carats, :numericality => true

3c. For example, in app/views/cut_diamonds/show.html.erb:
       <h1>Information for CutDiamond 
       <%= @cut_diamond.id %></h1>
    In app/views/diamond_brokers/show.html.erb:
       <h1>Information for Diamond Dealer 
           <%= @diamond_broker.name %></h1>

3d. Change the h1 headers on the index views
    app/views/cut_diamonds/index.html.erb and
    app/views/diamond_dealers/index.html.erb.

3e. In app/views/cut_diamonds/index.html.erb, add these lines to the
    table:
    <th>Broker ID</th>

    <td><%= cut_diamond.diamond_broker.name %></td>

3f. In app/views/cut_diamonds/_form.html.erb add this code between the
    clarity text_field and the submit button:
    <div class="field">
       <%= f.label :Diamond Broker ID %><br />
       <%= f.text_field :diamond_broker_id %>
    </div>

3g. In app/views/cut_diamonds/_form.html.erb, replace the code
    <%= f.text_field :clarity %>
    by
    <%= f.submit :clarity, [["Flawless", "F",
                             "SlightlyIncluded", "SI", 
                             "Included", "I"]]  %>
    
3h. In app/views/diamond_brokers/index.html.erb, add these lines to the table:
    <th>Diamond Count</th>

    <td><%= diamond_broker.diamonds.count %></td>   

3i. On the layout page app/views/layouts/application.html.erb, add this line:
    <%= image_tag 'sparkling_diamonds.jpg' %>

3j. In app/assets/stylesheets/scaffold.css.scss
    a { color: #800000 }

3k. In app/assets/stylesheets/scaffold.css.scss
    h1 { font-weight: bold;
         font-style: italic;
         color: #008080; }

3i. In app/views/diamond_brokers/index.htm
    <p>We have access to 
       <%= DiamondBrokers.count %> that have a total of
       <%= CutDiamond.count %> cut diamonds.</p>