


Source Code for cut_diamonds controller in 
the Rails ChicagoDiamonds project

app/controllers/cut_diamonds_controller.rb     Pages 2 and 3

app/views/cut_diamonds/_form.erb.html          Page 4

app/views/cut_diamonds/index.erb.html          Page 5

app/views/layouts/application.erb.html         Page 5

app/views/cut_diamonds/show.erb.html           Page 6

app/views/cut_diamonds/new.erb.html            Page 6

app/views/cut_diamonds/edit.erb.html           Page 6

app/models/cut_diamond.rb                      Page 7

app/models/store.rb                            Page 7

public/stylesheets/scaffold.css                Page 8


                                                                Page 2
=====================================================
File name: app/controllers/cut_diamonds_controller.rb
=====================================================

class CutDiamondsController < ApplicationController
  # GET /cut_diamonds
  # GET /cut_diamonds.xml
  def index
    @cut_diamonds = CutDiamond.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cut_diamonds }
    end
  end

  # GET /cut_diamonds/1
  # GET /cut_diamonds/1.xml
  def show
    @cut_diamond = CutDiamond.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @cut_diamond }
    end
  end

  # GET /cut_diamonds/new
  # GET /cut_diamonds/new.xml
  def new
    @cut_diamond = CutDiamond.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @cut_diamond }
    end
  end

  # GET /cut_diamonds/1/edit
  def edit
    @cut_diamond = CutDiamond.find(params[:id])
  end



                                                                Page 3
================================================================
File name: app/controllers/cut_diamonds_controller.rb, continued
================================================================

  # POST /cut_diamonds
  # POST /cut_diamonds.xml
  def create
    @cut_diamond = CutDiamond.new(params[:cut_diamond])

    respond_to do |format|
      if @cut_diamond.save
        format.html { redirect_to(@cut_diamond, 
           :notice => 'Cut diamond was successfully created.') }
        format.xml  { render :xml => @cut_diamond, 
           :status => :created, :location => @cut_diamond }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @cut_diamond.errors, 
           :status => :unprocessable_entity }
      end
    end
  end


  # PUT /cut_diamonds/1
  # PUT /cut_diamonds/1.xml
  def update
    @cut_diamond = CutDiamond.find(params[:id])

    respond_to do |format|
      if @cut_diamond.update_attributes(params[:cut_diamond])
        format.html { redirect_to(@cut_diamond, 
            :notice => 'Cut diamond was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @cut_diamond.errors, 
            :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /cut_diamonds/1
  # DELETE /cut_diamonds/1.xml
  def destroy
    @cut_diamond = CutDiamond.find(params[:id])
    @cut_diamond.destroy

    respond_to do |format|
      format.html { redirect_to(cut_diamonds_url) }
      format.xml  { head :ok }
    end
  end
end




                                                                Page 4
================================================
File name: app/views/cut_diamonds/_form.html.erb
================================================

<%= form_for(@cut_diamond) do |f| %>
  <% if @cut_diamond.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@cut_diamond.errors.count, "error") %> 
         prohibited this cut_diamond from being saved:</h2>

      <ul>
      <% @cut_diamond.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :weight %><br />
    <%= f.text_field :weight %>
  </div>
  <div class="field">
    <%= f.label :clarity %><br />
    <%= f.text_field :clarity %>
  </div>
  <div class="field">
    <%= f.label :photo %><br />
    <%= f.text_field :photo %>
  </div>
  <div class="field">
    <%= f.label :store_id %><br />
    <%= f.text_field :store_id %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>




                                                                Page 5
================================================
File name: app/views/cut_diamonds/index.html.erb
================================================
<h1>Listing cut_diamonds</h1>

<table>
  <tr>
    <th>Weight</th>
    <th>Clarity</th>
    <th>Photo</th>
    <th>Store</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @cut_diamonds.each do |cut_diamond| %>
  <tr>
    <td><%= cut_diamond.weight %></td>
    <td><%= cut_diamond.clarity %></td>
    <td><%= cut_diamond.photo %></td>
    <td><%= cut_diamond.store_id %></td>
    <td><%= link_to 'Show', cut_diamond %></td>
    <td><%= link_to 'Edit', edit_cut_diamond_path(cut_diamond) %></td>
    <td><%= link_to 'Destroy', cut_diamond, 
        :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Cut diamond', new_cut_diamond_path %>

=================================================
File name: app/views/layouts/application.html.erb
=================================================

<!DOCTYPE html>
<html>
<head>
  <title>ChicagoDiamonds</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>



                                                                Page 6
================================================
File name: app/views/cut_diamonds/show.html.erb
================================================

<p id="notice"><%= notice %></p>

<p>
  <b>Weight:</b>
  <%= @cut_diamond.weight %>
</p>

<p>
  <b>Clarity:</b>
  <%= @cut_diamond.clarity %>
</p>

<p>
  <b>Photo:</b>
  <%= @cut_diamond.photo %>
</p>

<p>
  <b>Store:</b>
  <%= @cut_diamond.store_id %>
</p>


<%= link_to 'Edit', edit_cut_diamond_path(@cut_diamond) %> |
<%= link_to 'Back', cut_diamonds_path %>

================================================
File name: app/views/cut_diamonds/new.html.erb
================================================

<h1>New cut_diamond</h1>

<%= render 'form' %>

<%= link_to 'Back', cut_diamonds_path %>

================================================
File name: app/views/cut_diamonds/edit.html.erb
================================================

<h1>Editing cut_diamond</h1>

<%= render 'form' %>

<%= link_to 'Show', @cut_diamond %> |
<%= link_to 'Back', cut_diamonds_path %>



                                                                Page 7
====================================
File name: app/models/cut_diamond.rb
====================================

class CutDiamond < ActiveRecord::Base



end

====================================
File name: app/models/store.rb
====================================

class Store < ActiveRecord::Base



end

                                                                Page 8
==========================================
File name: public/stylesheets/scaffold.css
==========================================

body { background-color: #fff; color: #333; }

body, p, ol, ul, td {
  font-family: verdana, arial, helvetica, sans-serif;
  font-size:   13px;
  line-height: 18px;
}

pre {
  background-color: #eee;
  padding: 10px;
  font-size: 11px;
}

a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }

div.field, div.actions {
  margin-bottom: 10px;
}

#notice {
  color: green;
}

.field_with_errors {
  padding: 2px;
  background-color: red;
  display: table;
}

#error_explanation {
  width: 450px;
  border: 2px solid red;
  padding: 7px;
  padding-bottom: 0;
  margin-bottom: 20px;
  background-color: #f0f0f0;
}

#error_explanation h2 {
  text-align: left;
  font-weight: bold;
  padding: 5px 5px 5px 15px;
  font-size: 12px;
  margin: -7px;
  margin-bottom: 0px;
  background-color: #c00;
  color: #fff;
}

#error_explanation ul li {
  font-size: 12px;
  list-style: square;
}
