Skip to content

Commit

Permalink
added person resource and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
linojon committed Mar 18, 2012
1 parent 8032bba commit 534cbdf
Show file tree
Hide file tree
Showing 27 changed files with 717 additions and 22 deletions.
3 changes: 3 additions & 0 deletions 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/
83 changes: 83 additions & 0 deletions 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 :no_content }
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 :no_content }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/people_helper.rb
@@ -0,0 +1,2 @@
module PeopleHelper
end
2 changes: 2 additions & 0 deletions app/models/person.rb
@@ -0,0 +1,2 @@
class Person < ActiveRecord::Base
end
20 changes: 20 additions & 0 deletions app/views/people/_form.html.haml
@@ -0,0 +1,20 @@
= simple_form_for(@person) do |f|
= f.error_notification

.form-inputs
= f.input :last_name
= f.input :first_name
= f.input :middle_name
= f.input :maden
= f.input :prefix
= f.input :suffix
= f.input :gender
= f.input :birth_date
= f.input :death_date
= f.input :death_hebrew_date_day
= f.input :death_hebrew_date_month
= f.input :death_hebrew_date_year
= f.input :death_after_sunset

.form-actions
= f.button :wrapped, :cancel => people_path
7 changes: 7 additions & 0 deletions app/views/people/edit.html.haml
@@ -0,0 +1,7 @@
%h1 Editing person

= render 'form'

= link_to 'Show', @person
\|
= link_to 'Back', people_path
43 changes: 43 additions & 0 deletions app/views/people/index.html.haml
@@ -0,0 +1,43 @@
%h1 Listing people

%table
%tr
%th Last name
%th First name
%th Middle name
%th Maden
%th Prefix
%th Suffix
%th Gender
%th Birth date
%th Death date
%th Death hebrew date day
%th Death hebrew date month
%th Death hebrew date year
%th Death after sunset
%th
%th
%th

- @people.each do |person|
%tr
%td= person.last_name
%td= person.first_name
%td= person.middle_name
%td= person.maden
%td= person.prefix
%td= person.suffix
%td= person.gender
%td= person.birth_date
%td= person.death_date
%td= person.death_hebrew_date_day
%td= person.death_hebrew_date_month
%td= person.death_hebrew_date_year
%td= person.death_after_sunset
%td= link_to 'Show', person
%td= link_to 'Edit', edit_person_path(person)
%td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete

%br

= link_to 'New Person', new_person_path
5 changes: 5 additions & 0 deletions app/views/people/new.html.haml
@@ -0,0 +1,5 @@
%h1 New person

= render 'form'

= link_to 'Back', people_path
45 changes: 45 additions & 0 deletions app/views/people/show.html.haml
@@ -0,0 +1,45 @@
%p#notice= notice

%p
%b Last name:
= @person.last_name
%p
%b First name:
= @person.first_name
%p
%b Middle name:
= @person.middle_name
%p
%b Maden:
= @person.maden
%p
%b Prefix:
= @person.prefix
%p
%b Suffix:
= @person.suffix
%p
%b Gender:
= @person.gender
%p
%b Birth date:
= @person.birth_date
%p
%b Death date:
= @person.death_date
%p
%b Death hebrew date day:
= @person.death_hebrew_date_day
%p
%b Death hebrew date month:
= @person.death_hebrew_date_month
%p
%b Death hebrew date year:
= @person.death_hebrew_date_year
%p
%b Death after sunset:
= @person.death_after_sunset

= link_to 'Edit', edit_person_path(@person)
\|
= link_to 'Back', people_path
10 changes: 2 additions & 8 deletions config/application.rb
Expand Up @@ -23,6 +23,7 @@ class Application < Rails::Application

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib/extras)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down Expand Up @@ -63,13 +64,6 @@ class Application < Rails::Application
config.assets.version = '1.0'

config.assets.initialize_on_precompile = false

config.generators do |g|
g.form_builder :simple_form
g.template_engine :haml
g.test_framework :rspec, :fixture => true
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end


end
end
3 changes: 3 additions & 0 deletions config/initializers/simple_form.rb
@@ -1,3 +1,5 @@
require 'simple_form_extensions'

# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
Expand Down Expand Up @@ -137,6 +139,7 @@

# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form
config.form_class = 'simple_form form-horizontal'

# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]
Expand Down
5 changes: 5 additions & 0 deletions config/locales/simple_form.en.yml
Expand Up @@ -21,4 +21,9 @@ en:
# hints:
# username: 'User name to sign in.'
# password: 'No special characters, please.'
creating: "Creating..."
updating: 'Updating...'
buttons:
or: 'or'
cancel: 'cancel'

2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,5 +1,7 @@
Ym32::Application.routes.draw do

resources :people

match 'about' => 'pages#about'
root :to => 'pages#home'

Expand Down
21 changes: 21 additions & 0 deletions db/migrate/20120318022557_create_people.rb
@@ -0,0 +1,21 @@
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :last_name
t.string :first_name
t.string :middle_name
t.string :maden
t.string :prefix
t.string :suffix
t.string :gender
t.date :birth_date
t.date :death_date
t.integer :death_hebrew_date_day
t.integer :death_hebrew_date_month
t.integer :death_hebrew_date_year
t.boolean :death_after_sunset

t.timestamps
end
end
end
20 changes: 19 additions & 1 deletion db/schema.rb
Expand Up @@ -11,6 +11,24 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20120318022557) do

create_table "people", :force => true do |t|
t.string "last_name"
t.string "first_name"
t.string "middle_name"
t.string "maden"
t.string "prefix"
t.string "suffix"
t.string "gender"
t.date "birth_date"
t.date "death_date"
t.integer "death_hebrew_date_day"
t.integer "death_hebrew_date_month"
t.integer "death_hebrew_date_year"
t.boolean "death_after_sunset"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
37 changes: 24 additions & 13 deletions doc/step by step.txt
Expand Up @@ -28,17 +28,12 @@ Gemfile
gem 'haml-rails'
gem 'simple_form'

config/application.rb
config.generators do |g|
g.form_builder :simple_form
g.template_engine :haml
end

$ bundle
$ rails g simple_form:install

$ rails g scaffold
=> Template engine: Default: haml
Fixture replacement: Default: factory_girl
Form builder: Default: simple_form

## ---------------
Expand All @@ -54,12 +49,6 @@ Gemfile
gem "capybara"
end

config/application.rb
config.generators do |g|
g.test_framework :rspec, :fixture => true
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end

$ bundle install
$ rails g rspec:install
FAILS
Expand Down Expand Up @@ -215,6 +204,21 @@ simple_form (again)

= simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|

tweaks to simple_form for bootstrap
https://github.com/plataformatec/simple_form/wiki/Twitter-Bootstrap-v2-and-simple_form-v2
config/initializers/simple_form.rb
config.form_class = 'simple_form form-horizontal'
lib/extras/simple_form_extension.rb
...see wiki
config/application.rb
config.autoload_paths += %W(#{config.root}/lib/extras)
config/locales/simple_form.en.yml
...
views/people/_form.html.haml
replace f.button :submit with
= f.button :wrapped, :cancel => people_path


using sass instead of less
Gemfile
gem 'bootstrap-sass'
Expand All @@ -231,7 +235,14 @@ re-deploy


## ---------------
##
## people

$ rails g scaffold person last_name first_name middle_name maden prefix suffix gender birth_date:date death_date:date death_hebrew_date_day:integer death_hebrew_date_month:integer death_hebrew_date_year:integer death_after_sunset:boolean --skip-stylesheets

$ rake db:migrate
$ rails s


## ---------------
##
## ---------------
Expand Down

0 comments on commit 534cbdf

Please sign in to comment.