Skip to content

Commit

Permalink
Added Adjunct Addition with foreign key to Adjunct Types. Added dropd…
Browse files Browse the repository at this point in the history
…own for new and create. Added text descriptions in list and show
  • Loading branch information
omar committed Mar 25, 2010
1 parent 9a753e6 commit c7503c8
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 2 deletions.
85 changes: 85 additions & 0 deletions app/controllers/adjunct_additions_controller.rb
@@ -0,0 +1,85 @@
class AdjunctAdditionsController < ApplicationController
# GET /adjunct_additions
# GET /adjunct_additions.xml
def index
@adjunct_additions = AdjunctAddition.all

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

# GET /adjunct_additions/1
# GET /adjunct_additions/1.xml
def show
@adjunct_addition = AdjunctAddition.find(params[:id])

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

# GET /adjunct_additions/new
# GET /adjunct_additions/new.xml
def new
@adjunct_addition = AdjunctAddition.new

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

# GET /adjunct_additions/1/edit
def edit
@adjunct_addition = AdjunctAddition.find(params[:id])
end

# POST /adjunct_additions
# POST /adjunct_additions.xml
def create
@adjunct_addition = AdjunctAddition.new(params[:adjunct_addition])

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

# PUT /adjunct_additions/1
# PUT /adjunct_additions/1.xml
def update
@adjunct_addition = AdjunctAddition.find(params[:id])

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

# DELETE /adjunct_additions/1
# DELETE /adjunct_additions/1.xml
def destroy
@adjunct_addition = AdjunctAddition.find(params[:id])
@adjunct_addition.destroy

respond_to do |format|
format.html { redirect_to(adjunct_additions_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/adjunct_additions_helper.rb
@@ -0,0 +1,2 @@
module AdjunctAdditionsHelper
end
2 changes: 2 additions & 0 deletions app/models/adjunct_addition.rb
@@ -0,0 +1,2 @@
class AdjunctAddition < ActiveRecord::Base
end
28 changes: 28 additions & 0 deletions app/views/adjunct_additions/edit.html.erb
@@ -0,0 +1,28 @@
<h1>Editing adjunct_addition</h1>

<% form_for(@adjunct_addition) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :adjunct_type_id %><br />
<%= f.collection_select(:adjunct_type_id, AdjunctType.all, :id, :name) %> <br />
</p>
<p>
<%= f.label :time %><br />
<%= f.text_field :time %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :secondary %><br />
<%= f.check_box :secondary %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
<%= link_to 'Show', @adjunct_addition %> |
<%= link_to 'Back', adjunct_additions_path %>
26 changes: 26 additions & 0 deletions app/views/adjunct_additions/index.html.erb
@@ -0,0 +1,26 @@
<h1>Listing adjunct_additions</h1>

<table>
<tr>
<th>Adjunct type</th>
<th>Time</th>
<th>Amount</th>
<th>Secondary</th>
</tr>

<% @adjunct_additions.each do |adjunct_addition| %>
<tr>
<td><%=h AdjunctType.find(adjunct_addition.adjunct_type_id).name %></td>
<td><%=h adjunct_addition.time %></td>
<td><%=h adjunct_addition.amount %></td>
<td><%=h adjunct_addition.secondary %></td>
<td><%= link_to 'Show', adjunct_addition %></td>
<td><%= link_to 'Edit', edit_adjunct_addition_path(adjunct_addition) %></td>
<td><%= link_to 'Destroy', adjunct_addition, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New adjunct_addition', new_adjunct_addition_path %>
27 changes: 27 additions & 0 deletions app/views/adjunct_additions/new.html.erb
@@ -0,0 +1,27 @@
<h1>New adjunct_addition</h1>

<% form_for(@adjunct_addition) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :adjunct_type_id %><br />
<%= f.collection_select(:adjunct_type_id, AdjunctType.all, :id, :name) %> <br />
</p>
<p>
<%= f.label :time %><br />
<%= f.text_field :time %>
</p>
<p>
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</p>
<p>
<%= f.label :secondary %><br />
<%= f.check_box :secondary %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', adjunct_additions_path %>
23 changes: 23 additions & 0 deletions app/views/adjunct_additions/show.html.erb
@@ -0,0 +1,23 @@
<p>
<b>Adjunct type:</b>
<%=h AdjunctType.find(@adjunct_addition.adjunct_type_id).name %>
</p>

<p>
<b>Time:</b>
<%=h @adjunct_addition.time %>
</p>

<p>
<b>Amount:</b>
<%=h @adjunct_addition.amount %>
</p>

<p>
<b>Secondary:</b>
<%=h @adjunct_addition.secondary %>
</p>


<%= link_to 'Edit', edit_adjunct_addition_path(@adjunct_addition) %> |
<%= link_to 'Back', adjunct_additions_path %>
5 changes: 4 additions & 1 deletion app/views/index/index.html.erb
Expand Up @@ -4,5 +4,8 @@ Batches<br/>
Ingredients<br/>
<%= link_to "Yeast Types (#{YeastType.count})", yeast_types_path %><br/>
<%= link_to "Hops_Types (#{HopsType.count})", hops_types_path %><br/>

<%= link_to "Adjunct_Additions (#{AdjunctAddition.count})", adjunct_additions_path %><br/>
<%= link_to "Adjunct_Types (#{AdjunctType.count})", adjunct_types_path %><br/>
<%= link_to "Malt_Types (#{MaltType.count})", malt_types_path %><br/>

<%= link_to "Malt_Types (#{MaltType.count})", malt_types_path %><br/>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :adjunct_additions

map.resources :malt_types

map.resources :adjunct_types
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20100324232557_create_adjunct_additions.rb
@@ -0,0 +1,16 @@
class CreateAdjunctAdditions < ActiveRecord::Migration
def self.up
create_table :adjunct_additions do |t|
t.integer :adjunct_type_id
t.integer :time
t.float :amount
t.boolean :secondary

t.timestamps
end
end

def self.down
drop_table :adjunct_additions
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,16 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100324224941) do
ActiveRecord::Schema.define(:version => 20100324232557) do

create_table "adjunct_additions", :force => true do |t|
t.integer "adjunct_type_id"
t.integer "time"
t.float "amount"
t.boolean "secondary"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "adjunct_types", :force => true do |t|
t.string "name"
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/adjunct_additions.yml
@@ -0,0 +1,13 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
adjunct_type_id: 1
time: 1
amount: 1.5
secondary: false

two:
adjunct_type_id: 1
time: 1
amount: 1.5
secondary: false
45 changes: 45 additions & 0 deletions test/functional/adjunct_additions_controller_test.rb
@@ -0,0 +1,45 @@
require 'test_helper'

class AdjunctAdditionsControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:adjunct_additions)
end

test "should get new" do
get :new
assert_response :success
end

test "should create adjunct_addition" do
assert_difference('AdjunctAddition.count') do
post :create, :adjunct_addition => { }
end

assert_redirected_to adjunct_addition_path(assigns(:adjunct_addition))
end

test "should show adjunct_addition" do
get :show, :id => adjunct_additions(:one).to_param
assert_response :success
end

test "should get edit" do
get :edit, :id => adjunct_additions(:one).to_param
assert_response :success
end

test "should update adjunct_addition" do
put :update, :id => adjunct_additions(:one).to_param, :adjunct_addition => { }
assert_redirected_to adjunct_addition_path(assigns(:adjunct_addition))
end

test "should destroy adjunct_addition" do
assert_difference('AdjunctAddition.count', -1) do
delete :destroy, :id => adjunct_additions(:one).to_param
end

assert_redirected_to adjunct_additions_path
end
end
8 changes: 8 additions & 0 deletions test/unit/adjunct_addition_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class AdjunctAdditionTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
4 changes: 4 additions & 0 deletions test/unit/helpers/adjunct_additions_helper_test.rb
@@ -0,0 +1,4 @@
require 'test_helper'

class AdjunctAdditionsHelperTest < ActionView::TestCase
end

0 comments on commit c7503c8

Please sign in to comment.