Permalink
Browse files

person scaffold

  • Loading branch information...
1 parent c38206f commit 60ec0c8f3c1ac85158ffb01ff14ad8ca7349708d @sellittf sellittf committed Jun 8, 2011
View
3 app/assets/javascripts/people.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
5 app/assets/stylesheets/people.css.scss
@@ -0,0 +1,5 @@
+/*
+ Place all the styles related to the matching controller here.
+ They will automatically be included in application.css.
+ You can use Sass (SCSS) here: http://sass-lang.com/
+*/
View
58 app/assets/stylesheets/scaffold.css.scss
@@ -0,0 +1,58 @@
+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;
+ &:visited { color: #666; }
+ &: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;
+
+ 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;
+ }
+
+ ul li {
+ font-size: 12px;
+ list-style: square;
+ }
+}
View
83 app/controllers/people_controller.rb
@@ -0,0 +1,83 @@
+class PeopleController < ApplicationController
+ # GET /people
+ # GET /people.json
+ def index
+ @people = Person.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @people }
+ end
+ end
+
+ # GET /people/1
+ # GET /people/1.json
+ def show
+ @person = Person.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @person }
+ end
+ end
+
+ # GET /people/new
+ # GET /people/new.json
+ def new
+ @person = Person.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render :json => @person }
+ end
+ end
+
+ # GET /people/1/edit
+ def edit
+ @person = Person.find(params[:id])
+ end
+
+ # POST /people
+ # POST /people.json
+ def create
+ @person = Person.new(params[:person])
+
+ respond_to do |format|
+ if @person.save
+ format.html { redirect_to @person, :notice => 'Person was successfully created.' }
+ format.json { render :json => @person, :status => :created, :location => @person }
+ else
+ format.html { render :action => "new" }
+ format.json { render :json => @person.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /people/1
+ # PUT /people/1.json
+ def update
+ @person = Person.find(params[:id])
+
+ respond_to do |format|
+ if @person.update_attributes(params[:person])
+ format.html { redirect_to @person, :notice => 'Person was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.json { render :json => @person.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /people/1
+ # DELETE /people/1.json
+ def destroy
+ @person = Person.find(params[:id])
+ @person.destroy
+
+ respond_to do |format|
+ format.html { redirect_to people_url }
+ format.json { head :ok }
+ end
+ end
+end
View
2 app/helpers/people_helper.rb
@@ -0,0 +1,2 @@
+module PeopleHelper
+end
View
2 app/models/person.rb
@@ -0,0 +1,2 @@
+class Person < ActiveRecord::Base
+end
View
21 app/views/people/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_for(@person) do |f| %>
+ <% if @person.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@person.errors.count, "error") %> prohibited this person from being saved:</h2>
+
+ <ul>
+ <% @person.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/people/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing person</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @person %> |
+<%= link_to 'Back', people_path %>
View
23 app/views/people/index.html.erb
@@ -0,0 +1,23 @@
+<h1>Listing people</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @people.each do |person| %>
+ <tr>
+ <td><%= person.name %></td>
+ <td><%= link_to 'Show', person %></td>
+ <td><%= link_to 'Edit', edit_person_path(person) %></td>
+ <td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Person', new_person_path %>
View
5 app/views/people/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New person</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', people_path %>
View
10 app/views/people/show.html.erb
@@ -0,0 +1,10 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @person.name %>
+</p>
+
+
+<%= link_to 'Edit', edit_person_path(@person) %> |
+<%= link_to 'Back', people_path %>
View
9 db/migrate/20110608174055_create_people.rb
@@ -0,0 +1,9 @@
+class CreatePeople < ActiveRecord::Migration
+ def change
+ create_table :people do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
View
7 test/fixtures/people.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
View
49 test/functional/people_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PeopleControllerTest < ActionController::TestCase
+ setup do
+ @person = people(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:people)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create person" do
+ assert_difference('Person.count') do
+ post :create, :person => @person.attributes
+ end
+
+ assert_redirected_to person_path(assigns(:person))
+ end
+
+ test "should show person" do
+ get :show, :id => @person.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => @person.to_param
+ assert_response :success
+ end
+
+ test "should update person" do
+ put :update, :id => @person.to_param, :person => @person.attributes
+ assert_redirected_to person_path(assigns(:person))
+ end
+
+ test "should destroy person" do
+ assert_difference('Person.count', -1) do
+ delete :destroy, :id => @person.to_param
+ end
+
+ assert_redirected_to people_path
+ end
+end
View
4 test/unit/helpers/people_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PeopleHelperTest < ActionView::TestCase
+end
View
7 test/unit/person_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PersonTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit 60ec0c8

Please sign in to comment.