Permalink
Browse files

adds items scaffold

  • Loading branch information...
1 parent bcbeed0 commit fe3e5013a0ba8ecb4dd88a1ece8c22af89ccfd00 @chaserx chaserx committed Jul 6, 2012
View
3 app/assets/javascripts/items.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/items.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Items controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
83 app/controllers/items_controller.rb
@@ -0,0 +1,83 @@
+class ItemsController < ApplicationController
+ # GET /items
+ # GET /items.json
+ def index
+ @items = Item.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @items }
+ end
+ end
+
+ # GET /items/1
+ # GET /items/1.json
+ def show
+ @item = Item.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @item }
+ end
+ end
+
+ # GET /items/new
+ # GET /items/new.json
+ def new
+ @item = Item.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @item }
+ end
+ end
+
+ # GET /items/1/edit
+ def edit
+ @item = Item.find(params[:id])
+ end
+
+ # POST /items
+ # POST /items.json
+ def create
+ @item = Item.new(params[:item])
+
+ respond_to do |format|
+ if @item.save
+ format.html { redirect_to @item, notice: 'Item was successfully created.' }
+ format.json { render json: @item, status: :created, location: @item }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @item.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /items/1
+ # PUT /items/1.json
+ def update
+ @item = Item.find(params[:id])
+
+ respond_to do |format|
+ if @item.update_attributes(params[:item])
+ format.html { redirect_to @item, notice: 'Item was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @item.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /items/1
+ # DELETE /items/1.json
+ def destroy
+ @item = Item.find(params[:id])
+ @item.destroy
+
+ respond_to do |format|
+ format.html { redirect_to items_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2 app/helpers/items_helper.rb
@@ -0,0 +1,2 @@
+module ItemsHelper
+end
View
3 app/models/item.rb
@@ -0,0 +1,3 @@
+class Item < ActiveRecord::Base
+ attr_accessible :checked_in, :checked_out, :checked_out_by, :date_collected, :name, :tag_number
+end
View
16 app/views/items/_form.html.erb
@@ -0,0 +1,16 @@
+<%= simple_form_for(@item) do |f| %>
+ <%= f.error_notification %>
+
+ <div class="form-inputs">
+ <%= f.input :name %>
+ <%= f.input :date_collected %>
+ <%= f.input :checked_in %>
+ <%= f.input :checked_out %>
+ <%= f.input :checked_out_by %>
+ <%= f.input :tag_number %>
+ </div>
+
+ <div class="form-actions">
+ <%= f.button :submit %>
+ </div>
+<% end %>
View
6 app/views/items/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing item</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @item %> |
+<%= link_to 'Back', items_path %>
View
33 app/views/items/index.html.erb
@@ -0,0 +1,33 @@
+<h1>Listing items</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Date collected</th>
+ <th>Checked in</th>
+ <th>Checked out</th>
+ <th>Checked out by</th>
+ <th>Tag number</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @items.each do |item| %>
+ <tr>
+ <td><%= item.name %></td>
+ <td><%= item.date_collected %></td>
+ <td><%= item.checked_in %></td>
+ <td><%= item.checked_out %></td>
+ <td><%= item.checked_out_by %></td>
+ <td><%= item.tag_number %></td>
+ <td><%= link_to 'Show', item %></td>
+ <td><%= link_to 'Edit', edit_item_path(item) %></td>
+ <td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Item', new_item_path %>
View
5 app/views/items/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New item</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', items_path %>
View
35 app/views/items/show.html.erb
@@ -0,0 +1,35 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @item.name %>
+</p>
+
+<p>
+ <b>Date collected:</b>
+ <%= @item.date_collected %>
+</p>
+
+<p>
+ <b>Checked in:</b>
+ <%= @item.checked_in %>
+</p>
+
+<p>
+ <b>Checked out:</b>
+ <%= @item.checked_out %>
+</p>
+
+<p>
+ <b>Checked out by:</b>
+ <%= @item.checked_out_by %>
+</p>
+
+<p>
+ <b>Tag number:</b>
+ <%= @item.tag_number %>
+</p>
+
+
+<%= link_to 'Edit', edit_item_path(@item) %> |
+<%= link_to 'Back', items_path %>
View
2 config/routes.rb
@@ -1,4 +1,6 @@
Collector::Application.routes.draw do
+ resources :items
+
devise_for :users
get "pages/index"
View
14 db/migrate/20120706205014_create_items.rb
@@ -0,0 +1,14 @@
+class CreateItems < ActiveRecord::Migration
+ def change
+ create_table :items do |t|
+ t.string :name
+ t.datetime :date_collected
+ t.datetime :checked_in
+ t.datetime :checked_out
+ t.integer :checked_out_by
+ t.string :tag_number
+
+ t.timestamps
+ end
+ end
+end
View
17 test/fixtures/items.yml
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ date_collected: 2012-07-06 16:50:14
+ checked_in: 2012-07-06 16:50:14
+ checked_out: 2012-07-06 16:50:14
+ checked_out_by: 1
+ tag_number: MyString
+
+two:
+ name: MyString
+ date_collected: 2012-07-06 16:50:14
+ checked_in: 2012-07-06 16:50:14
+ checked_out: 2012-07-06 16:50:14
+ checked_out_by: 1
+ tag_number: MyString
View
49 test/functional/items_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ItemsControllerTest < ActionController::TestCase
+ setup do
+ @item = items(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:items)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create item" do
+ assert_difference('Item.count') do
+ post :create, item: { checked_in: @item.checked_in, checked_out: @item.checked_out, checked_out_by: @item.checked_out_by, date_collected: @item.date_collected, name: @item.name, tag_number: @item.tag_number }
+ end
+
+ assert_redirected_to item_path(assigns(:item))
+ end
+
+ test "should show item" do
+ get :show, id: @item
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @item
+ assert_response :success
+ end
+
+ test "should update item" do
+ put :update, id: @item, item: { checked_in: @item.checked_in, checked_out: @item.checked_out, checked_out_by: @item.checked_out_by, date_collected: @item.date_collected, name: @item.name, tag_number: @item.tag_number }
+ assert_redirected_to item_path(assigns(:item))
+ end
+
+ test "should destroy item" do
+ assert_difference('Item.count', -1) do
+ delete :destroy, id: @item
+ end
+
+ assert_redirected_to items_path
+ end
+end
View
4 test/unit/helpers/items_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ItemsHelperTest < ActionView::TestCase
+end
View
7 test/unit/item_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ItemTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit fe3e501

Please sign in to comment.