Permalink
Browse files

Implemented phone numbers

  • Loading branch information...
1 parent 4916d04 commit 01c6c8b1c6b8095377ff531fc0203436122ba968 @jcasimir committed Apr 19, 2011
View
@@ -10,4 +10,5 @@ group :development, :test do
gem 'unicorn'
gem 'nifty-generators'
gem "mocha"
-end
+ gem "capybara"
+end
View
@@ -30,17 +30,33 @@ GEM
activesupport (3.0.6)
arel (2.0.9)
builder (2.1.2)
+ capybara (0.4.1.2)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.9)
+ childprocess (0.1.8)
+ ffi (~> 1.0.6)
configuration (1.2.0)
+ culerity (0.2.15)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
+ ffi (1.0.7)
+ rake (>= 0.8.7)
heroku (1.20.1)
launchy (~> 0.3.2)
rest-client (>= 1.4.0, < 1.7.0)
i18n (0.5.0)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
+ json_pure (1.5.1)
kgio (2.3.3)
launchy (0.3.7)
configuration (>= 0.0.5)
@@ -53,6 +69,7 @@ GEM
mime-types (1.16)
mocha (0.9.12)
nifty-generators (0.4.6)
+ nokogiri (1.4.4)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
@@ -88,6 +105,12 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.5.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.4)
+ childprocess (>= 0.1.7)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
@@ -96,11 +119,14 @@ GEM
unicorn (3.5.0)
kgio (~> 2.3)
rack
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ capybara
heroku
jquery-rails
mocha
@@ -0,0 +1,41 @@
+class PhoneNumbersController < ApplicationController
+ def index
+ @phone_numbers = PhoneNumber.all
+ end
+
+ def show
+ @phone_number = PhoneNumber.find(params[:id])
+ end
+
+ def new
+ @phone_number = PhoneNumber.new(:person_id => params[:person_id])
+ end
+
+ def create
+ @phone_number = PhoneNumber.new(params[:phone_number])
+ if @phone_number.save
+ redirect_to @phone_number.person, :notice => "Successfully created phone number."
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @phone_number = PhoneNumber.find(params[:id])
+ end
+
+ def update
+ @phone_number = PhoneNumber.find(params[:id])
+ if @phone_number.update_attributes(params[:phone_number])
+ redirect_to @phone_number.person, :notice => "Successfully updated phone number."
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @phone_number = PhoneNumber.find(params[:id])
+ @phone_number.destroy
+ redirect_to @phone_number.person, :notice => "Successfully destroyed phone number."
+ end
+end
@@ -0,0 +1,11 @@
+module PhoneNumbersHelper
+
+ def print_numbers(numbers)
+ render :partial => "phone_number"
+ items = numbers.collect do |n|
+ content_tag(:li, n.number + link_to("edit", edit_phone_number_path(n))).html_safe
+ end
+
+ content_tag :ul, items.join.html_safe
+ end
+end
@@ -1,3 +1,7 @@
class Person < ActiveRecord::Base
attr_accessible :first_name, :last_name
+
+ validates_presence_of :first_name, :last_name
+
+ has_many :phone_numbers
end
@@ -0,0 +1,6 @@
+class PhoneNumber < ActiveRecord::Base
+ attr_accessible :number, :person_id
+ belongs_to :person
+
+ validates_presence_of :number, :person
+end
@@ -0,0 +1,9 @@
+<ul>
+ <% @person.phone_numbers.each do |phone_number| %>
+ <li>
+ <%= phone_number.number%>
+ <%= link_to "edit", edit_phone_number_path(phone_number) %>
+ <%= link_to "delete", phone_number_path(phone_number), :method => :delete, :id => "delete_phone_number_#{phone_number.id}" %>
+ </li>
+ <% end %>
+</ul>
@@ -4,11 +4,13 @@
<tr>
<th>First Name</th>
<th>Last Name</th>
+ <th>Phone Numbers</th>
</tr>
<% for person in @people %>
<tr>
<td><%= person.first_name %></td>
<td><%= person.last_name %></td>
+ <td><%= print_numbers person.phone_numbers %>
<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>
@@ -8,6 +8,12 @@
<strong>Last Name:</strong>
<%= @person.last_name %>
</p>
+<p>
+ <strong>Phone Numbers:</strong>
+ <%= render :partial => 'phone_numbers' %>
+</p>
+
+<%= link_to "Add a New Phone Number", new_phone_number_path(:person_id => @person.id ) %>
<p>
<%= link_to "Edit", edit_person_path(@person) %> |
@@ -0,0 +1,9 @@
+<%= form_for @phone_number do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :number %><br />
+ <%= f.text_field :number %>
+ </p>
+ <%= f.hidden_field :person_id %>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Phone Number" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @phone_number %> |
+ <%= link_to "View All", phone_numbers_path %>
+</p>
@@ -0,0 +1,19 @@
+<% title "Phone Numbers" %>
+
+<table>
+ <tr>
+ <th>Number</th>
+ <th>Person</th>
+ </tr>
+ <% for phone_number in @phone_numbers %>
+ <tr>
+ <td><%= phone_number.number %></td>
+ <td><%= phone_number.person_id %></td>
+ <td><%= link_to "Show", phone_number %></td>
+ <td><%= link_to "Edit", edit_phone_number_path(phone_number) %></td>
+ <td><%= link_to "Destroy", phone_number, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Phone Number", new_phone_number_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Phone Number" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", phone_numbers_path %></p>
@@ -0,0 +1,16 @@
+<% title "Phone Number" %>
+
+<p>
+ <strong>Number:</strong>
+ <%= @phone_number.number %>
+</p>
+<p>
+ <strong>Person:</strong>
+ <%= @phone_number.person_id %>
+</p>
+
+<p>
+ <%= link_to "Edit", edit_phone_number_path(@phone_number) %> |
+ <%= link_to "Destroy", @phone_number, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", phone_numbers_path %>
+</p>
View
@@ -1,4 +1,6 @@
JSContact::Application.routes.draw do
+ resources :phone_numbers
+
resources :people
# The priority is based upon order of creation:
@@ -0,0 +1,13 @@
+class CreatePhoneNumbers < ActiveRecord::Migration
+ def self.up
+ create_table :phone_numbers do |t|
+ t.string :number
+ t.integer :person_id
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :phone_numbers
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110417205708) do
+ActiveRecord::Schema.define(:version => 20110419134754) do
create_table "people", :force => true do |t|
t.string "first_name"
@@ -19,4 +19,11 @@
t.datetime "updated_at"
end
+ create_table "phone_numbers", :force => true do |t|
+ t.string "number"
+ t.integer "person_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
end
Oops, something went wrong.

0 comments on commit 01c6c8b

Please sign in to comment.