Skip to content

Commit

Permalink
person scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
Franco Sellitto committed Jun 8, 2011
1 parent c38206f commit 60ec0c8
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/people.js.coffee
Original file line number Original file line Diff line number Diff line change
@@ -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/
5 changes: 5 additions & 0 deletions app/assets/stylesheets/people.css.scss
Original file line number Original file line Diff line number Diff line change
@@ -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/
*/
58 changes: 58 additions & 0 deletions app/assets/stylesheets/scaffold.css.scss
Original file line number Original file line Diff line number Diff line change
@@ -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;
}
}
83 changes: 83 additions & 0 deletions app/controllers/people_controller.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/people_helper.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
module PeopleHelper
end
2 changes: 2 additions & 0 deletions app/models/person.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,2 @@
class Person < ActiveRecord::Base
end
21 changes: 21 additions & 0 deletions app/views/people/_form.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -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 %>
6 changes: 6 additions & 0 deletions app/views/people/edit.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing person</h1>

<%= render 'form' %>
<%= link_to 'Show', @person %> |
<%= link_to 'Back', people_path %>
23 changes: 23 additions & 0 deletions app/views/people/index.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -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 %>
5 changes: 5 additions & 0 deletions app/views/people/new.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New person</h1>

<%= render 'form' %>
<%= link_to 'Back', people_path %>
10 changes: 10 additions & 0 deletions app/views/people/show.html.erb
Original file line number Original file line Diff line number Diff line change
@@ -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 %>
9 changes: 9 additions & 0 deletions db/migrate/20110608174055_create_people.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name

t.timestamps
end
end
end
7 changes: 7 additions & 0 deletions test/fixtures/people.yml
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html

one:
name: MyString

two:
name: MyString
49 changes: 49 additions & 0 deletions test/functional/people_controller_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/unit/helpers/people_helper_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class PeopleHelperTest < ActionView::TestCase
end
7 changes: 7 additions & 0 deletions test/unit/person_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -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.