Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
428 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ group :development, :test do | |
gem 'unicorn' | ||
gem 'nifty-generators' | ||
gem "mocha" | ||
end | ||
gem "capybara" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class PhoneNumber < ActiveRecord::Base | ||
attr_accessible :number, :person_id | ||
belongs_to :person | ||
|
||
validates_presence_of :number, :person | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% title "Edit Phone Number" %> | ||
<%= render 'form' %> | ||
|
||
<p> | ||
<%= link_to "Show", @phone_number %> | | ||
<%= link_to "View All", phone_numbers_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% title "New Phone Number" %> | ||
<%= render 'form' %> | ||
|
||
<p><%= link_to "Back to List", phone_numbers_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.