Index: /ruby/trunk/rails/cancerehr/app/controllers/people_controller.rb =================================================================== --- /ruby/trunk/rails/cancerehr/app/controllers/people_controller.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/controllers/people_controller.rb (revision 60) @@ -0,0 +1,85 @@ +class PeopleController < ApplicationController + # GET /people + # GET /people.xml + def index + @people = Person.find(:all) + + respond_to do |format| + format.html # index.html.erb + format.xml { render :xml => @people } + end + end + + # GET /people/1 + # GET /people/1.xml + def show + @person = Person.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.xml { render :xml => @person } + end + end + + # GET /people/new + # GET /people/new.xml + def new + @person = Person.new + + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @person } + end + end + + # GET /people/1/edit + def edit + @person = Person.find(params[:id]) + end + + # POST /people + # POST /people.xml + def create + @person = Person.new(params[:person]) + + respond_to do |format| + if @person.save + flash[:notice] = 'Person was successfully created.' + format.html { redirect_to(@person) } + format.xml { render :xml => @person, :status => :created, :location => @person } + else + format.html { render :action => "new" } + format.xml { render :xml => @person.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /people/1 + # PUT /people/1.xml + def update + @person = Person.find(params[:id]) + + respond_to do |format| + if @person.update_attributes(params[:person]) + flash[:notice] = 'Person was successfully updated.' + format.html { redirect_to(@person) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @person.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /people/1 + # DELETE /people/1.xml + def destroy + @person = Person.find(params[:id]) + @person.destroy + + respond_to do |format| + format.html { redirect_to(people_url) } + format.xml { head :ok } + end + end +end Index: /ruby/trunk/rails/cancerehr/app/helpers/people_helper.rb =================================================================== --- /ruby/trunk/rails/cancerehr/app/helpers/people_helper.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/helpers/people_helper.rb (revision 60) @@ -0,0 +1,2 @@ +module PeopleHelper +end Index: /ruby/trunk/rails/cancerehr/app/models/people.rb =================================================================== --- /ruby/trunk/rails/cancerehr/app/models/people.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/models/people.rb (revision 60) @@ -0,0 +1,2 @@ +class People < ActiveRecord::Base +end Index: /ruby/trunk/rails/cancerehr/app/models/person.rb =================================================================== --- /ruby/trunk/rails/cancerehr/app/models/person.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/models/person.rb (revision 60) @@ -0,0 +1,2 @@ +class Person < ActiveRecord::Base +end Index: /ruby/trunk/rails/cancerehr/app/views/layouts/people.html.erb =================================================================== --- /ruby/trunk/rails/cancerehr/app/views/layouts/people.html.erb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/views/layouts/people.html.erb (revision 60) @@ -0,0 +1,17 @@ + + + +
+ +<%= flash[:notice] %>
+ +<%= yield %> + + + Index: /ruby/trunk/rails/cancerehr/app/views/people/edit.html.erb =================================================================== --- /ruby/trunk/rails/cancerehr/app/views/people/edit.html.erb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/views/people/edit.html.erb (revision 60) @@ -0,0 +1,27 @@ +
+ Name
+ <%= f.text_field :name %>
+
+ Birthday
+ <%= f.date_select :birthday %>
+
+ Sex
+ <%= f.text_field :sex %>
+
+ <%= f.submit "Update" %> +
+<% end %> + +<%= link_to 'Show', @person %> | +<%= link_to 'Back', people_path %> Index: /ruby/trunk/rails/cancerehr/app/views/people/index.html.erb =================================================================== --- /ruby/trunk/rails/cancerehr/app/views/people/index.html.erb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/views/people/index.html.erb (revision 60) @@ -0,0 +1,24 @@ +Name | +Birthday | +Sex | +|||
---|---|---|---|---|---|
<%=h person.name %> | +<%=h person.birthday %> | +<%=h person.sex %> | +<%= link_to 'Show', person %> | +<%= link_to 'Edit', edit_person_path(person) %> | +<%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %> | +
+ Name
+ <%= f.text_field :name %>
+
+ Birthday
+ <%= f.date_select :birthday %>
+
+ Sex
+ <%= f.text_field :sex %>
+
+ <%= f.submit "Create" %> +
+<% end %> + +<%= link_to 'Back', people_path %> Index: /ruby/trunk/rails/cancerehr/app/views/people/show.html.erb =================================================================== --- /ruby/trunk/rails/cancerehr/app/views/people/show.html.erb (revision 60) +++ /ruby/trunk/rails/cancerehr/app/views/people/show.html.erb (revision 60) @@ -0,0 +1,18 @@ ++ Name: + <%=h @person.name %> +
+ ++ Birthday: + <%=h @person.birthday %> +
+ ++ Sex: + <%=h @person.sex %> +
+ + +<%= link_to 'Edit', edit_person_path(@person) %> | +<%= link_to 'Back', people_path %> Index: /ruby/trunk/rails/cancerehr/config/routes.rb =================================================================== --- /ruby/trunk/rails/cancerehr/config/routes.rb (revision 59) +++ /ruby/trunk/rails/cancerehr/config/routes.rb (revision 60) @@ -1,3 +1,8 @@ ActionController::Routing::Routes.draw do |map| + map.resources :people + + + map.resources :people + # The priority is based upon order of creation: first created -> highest priority. Index: /ruby/trunk/rails/cancerehr/db/migrate/001_create_users.rb =================================================================== --- /ruby/trunk/rails/cancerehr/db/migrate/001_create_users.rb (revision 59) +++ /ruby/trunk/rails/cancerehr/db/migrate/001_create_users.rb (revision 60) @@ -1,4 +1,7 @@ class CreateUsers < ActiveRecord::Migration def self.up + options = { + :options => "DEFAULT_CHAR_SET=utf8" + } create_table :users do |t| t.column :name, :string Index: /ruby/trunk/rails/cancerehr/db/migrate/002_create_people.rb =================================================================== --- /ruby/trunk/rails/cancerehr/db/migrate/002_create_people.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/db/migrate/002_create_people.rb (revision 60) @@ -0,0 +1,21 @@ +class CreatePeople < ActiveRecord::Migration + def self.up + create_table :people do |t| + t.column :legal_name, :string + t.column :other_name, :string + t.column :home_address, :string + t.column :postal_address, :string + t.column :home_contact, :string + t.column :phone_number, :string + t.column :sex, :string + t.column :date_of_birth, :date + t.column :place_of_birth, :string + + t.timestamps + end + end + + def self.down + drop_table :people + end +end Index: /ruby/trunk/rails/cancerehr/db/schema.rb =================================================================== --- /ruby/trunk/rails/cancerehr/db/schema.rb (revision 59) +++ /ruby/trunk/rails/cancerehr/db/schema.rb (revision 60) @@ -10,5 +10,13 @@ # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 1) do +ActiveRecord::Schema.define(:version => 2) do + + create_table "people", :force => true do |t| + t.string "name" + t.date "birthday" + t.string "sex" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "users", :force => true do |t| Index: /ruby/trunk/rails/cancerehr/log/test.log =================================================================== --- /ruby/trunk/rails/cancerehr/log/test.log (revision 59) +++ /ruby/trunk/rails/cancerehr/log/test.log (revision 60) @@ -0,0 +1,28 @@ + [4;36;1mSQL (0.000351)[0m [0;1mSELECT count(*) AS count_all FROM people [0m + + +Processing PeopleController#create (for 0.0.0.0 at 2008-05-20 22:42:40) [POST] + Session ID: + Parameters: {"action"=>"create", "controller"=>"people", "person"=>{}} + [4;35;1mPerson Create (0.000462)[0m [0mINSERT INTO people ("name", "updated_at", "birthday", "created_at") VALUES(NULL, '2008-05-20 22:42:40', NULL, '2008-05-20 22:42:40')[0m +Redirected to http://test.host/people/1 +Completed in 0.00810 (123 reqs/sec) | DB: 0.00081 (10%) | 302 Found [http://test.host/people?] + [4;36;1mSQL (0.000310)[0m [0;1mSELECT count(*) AS count_all FROM people [0m + [4;35;1mSQL (0.000315)[0m [0mSELECT count(*) AS count_all FROM people [0m + + +Processing PeopleController#index (for 0.0.0.0 at 2008-05-20 22:42:40) [GET] + Session ID: + Parameters: {"action"=>"index", "controller"=>"people"} + [4;36;1mPerson Load (0.000259)[0m [0;1mSELECT * FROM people [0m +Rendering template within layouts/people +Rendering people/index +Completed in 0.00503 (198 reqs/sec) | Rendering: 0.00406 (80%) | DB: 0.00088 (17%) | 200 OK [http://test.host/people] + + +Processing PeopleController#new (for 0.0.0.0 at 2008-05-20 22:42:40) [GET] + Session ID: + Parameters: {"action"=>"new", "controller"=>"people"} +Rendering template within layouts/people +Rendering people/new +Completed in 0.00329 (303 reqs/sec) | Rendering: 0.00279 (84%) | DB: 0.00000 (0%) | 200 OK [http://test.host/people/new] Index: /ruby/trunk/rails/cancerehr/public/stylesheets/scaffold.css =================================================================== --- /ruby/trunk/rails/cancerehr/public/stylesheets/scaffold.css (revision 60) +++ /ruby/trunk/rails/cancerehr/public/stylesheets/scaffold.css (revision 60) @@ -0,0 +1,74 @@ +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; } + +.fieldWithErrors { + padding: 2px; + background-color: red; + display: table; +} + +#errorExplanation { + width: 400px; + border: 2px solid red; + padding: 7px; + padding-bottom: 12px; + margin-bottom: 20px; + background-color: #f0f0f0; +} + +#errorExplanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px; + background-color: #c00; + color: #fff; +} + +#errorExplanation p { + color: #333; + margin-bottom: 0; + padding: 5px; +} + +#errorExplanation ul li { + font-size: 12px; + list-style: square; +} + +div.uploadStatus { + margin: 5px; +} + +div.progressBar { + margin: 5px; +} + +div.progressBar div.border { + background-color: #fff; + border: 1px solid gray; + width: 100%; +} + +div.progressBar div.background { + background-color: #333; + height: 18px; + width: 0%; +} + Index: /ruby/trunk/rails/cancerehr/test/fixtures/people.yml =================================================================== --- /ruby/trunk/rails/cancerehr/test/fixtures/people.yml (revision 60) +++ /ruby/trunk/rails/cancerehr/test/fixtures/people.yml (revision 60) @@ -0,0 +1,11 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: MyString + birthday: 2008-05-21 + sex: MyString + +two: + name: MyString + birthday: 2008-05-21 + sex: MyString Index: /ruby/trunk/rails/cancerehr/test/functional/people_controller_test.rb =================================================================== --- /ruby/trunk/rails/cancerehr/test/functional/people_controller_test.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/test/functional/people_controller_test.rb (revision 60) @@ -0,0 +1,45 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleControllerTest < ActionController::TestCase + def test_should_get_index + get :index + assert_response :success + assert_not_nil assigns(:people) + end + + def test_should_get_new + get :new + assert_response :success + end + + def test_should_create_person + assert_difference('Person.count') do + post :create, :person => { } + end + + assert_redirected_to person_path(assigns(:person)) + end + + def test_should_show_person + get :show, :id => people(:one).id + assert_response :success + end + + def test_should_get_edit + get :edit, :id => people(:one).id + assert_response :success + end + + def test_should_update_person + put :update, :id => people(:one).id, :person => { } + assert_redirected_to person_path(assigns(:person)) + end + + def test_should_destroy_person + assert_difference('Person.count', -1) do + delete :destroy, :id => people(:one).id + end + + assert_redirected_to people_path + end +end Index: /ruby/trunk/rails/cancerehr/test/unit/people_test.rb =================================================================== --- /ruby/trunk/rails/cancerehr/test/unit/people_test.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/test/unit/people_test.rb (revision 60) @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleTest < ActiveSupport::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end Index: /ruby/trunk/rails/cancerehr/test/unit/person_test.rb =================================================================== --- /ruby/trunk/rails/cancerehr/test/unit/person_test.rb (revision 60) +++ /ruby/trunk/rails/cancerehr/test/unit/person_test.rb (revision 60) @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PersonTest < ActiveSupport::TestCase + # Replace this with your real tests. + def test_truth + assert true + end +end