Skip to content

Commit

Permalink
Merge pull request #9 from nzbrn/add_telephone_numbers
Browse files Browse the repository at this point in the history
Add telephone numbers
  • Loading branch information
Kale Worsley committed Feb 15, 2012
2 parents 93f07a2 + 7a09c36 commit 710800c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Expand Up @@ -271,6 +271,7 @@ def dashboard
end

def edit
current_user.phone_numbers.build
end

# this is the page that's shown after a new user is created via 3rd party provider_authorization
Expand Down
3 changes: 3 additions & 0 deletions app/models/phone_number.rb
@@ -0,0 +1,3 @@
class PhoneNumber < ActiveRecord::Base
belongs_to :user
end
6 changes: 5 additions & 1 deletion app/models/user.rb
Expand Up @@ -86,6 +86,10 @@ class User < ActiveRecord::Base
has_many :quality_metrics, :dependent => :destroy
has_many :sources, :dependent => :nullify
has_many :places, :dependent => :nullify
has_many :phone_numbers
accepts_nested_attributes_for :phone_numbers,
:allow_destroy => true,
:reject_if => proc { |attributes| attributes['label'].blank? or attributes['number'].blank? }

has_attached_file :icon,
:styles => { :medium => "300x300>", :thumb => "48x48#", :mini => "16x16#" },
Expand Down Expand Up @@ -135,7 +139,7 @@ def self.is_valid_year? (date)
# HACK HACK HACK -- how to do attr_accessible from here?
# prevents a user from submitting a crafted form that bypasses activation
# anything else you want your user to change should be added here.
attr_accessible :login, :email, :name, :password, :password_confirmation, :icon, :description, :time_zone, :icon_url, :gender, :year_of_birth, :first_name, :last_name, :address
attr_accessible :login, :email, :name, :password, :password_confirmation, :icon, :description, :time_zone, :icon_url, :gender, :year_of_birth, :first_name, :last_name, :address, :phone_numbers_attributes

named_scope :order, Proc.new { |sort_by, sort_dir|
sort_dir ||= 'DESC'
Expand Down
26 changes: 26 additions & 0 deletions app/views/users/edit.html.erb
Expand Up @@ -7,6 +7,13 @@
#preferencescol .field label{display:inline;}
#providercol ul{margin:0;padding:0;}
#providercol li{list-style-type:none;}
ul.address_list li {
list-style: none;
clear: both;
}
ul.address_list li span{
float: left;
}
</style>
<!--[if lt IE 7]>
<%= stylesheet_link_tag 'blueprint/ie' %>
Expand Down Expand Up @@ -84,6 +91,25 @@
<%= f.select(:gender,User::USER_GENDER, {:prompt => 'Select gender'}) %>
<%= f.select(:year_of_birth,(1900..Time.now.year).to_a.map{|i| [i,i]}, {:prompt => 'Select birth year'}) %>
</div>
<div class="column span-16">
<fieldset>
<legend>Phone Numbers</legend>
<ul class="address_list">
<li>
<span class="header phone_type span-3">Type</span>
<span class="header phone_number span-7">Number</span>
<span class="header phone_delete span-3">Delete</span>
</li>
<% f.fields_for :phone_numbers do |ff| %>
<li>
<span class="phone_type span-3"><%= ff.select :label, ["Work","Home", "Other"], {:label => false} %></span>
<span class="phone_number span-7"><%= ff.text_field :number , {:label => false}%></span>
<span class="phone_delete span-3"><%= ff.check_box :_destroy, {:label => false} %></span>
</li>
<% end %>
</ul>
</fieldset>
</div>
<div id="preferencescol" class="last column span-9">
<div class="stacked">
<label>Receive email notifications when people leave you</label>
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20120215023943_create_phone_numbers.rb
@@ -0,0 +1,15 @@
class CreatePhoneNumbers < ActiveRecord::Migration
def self.up
create_table :phone_numbers do |t|
t.string :label
t.string :number
t.integer :user_id

t.timestamps
end
end

def self.down
drop_table :phone_numbers
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120214214138) do
ActiveRecord::Schema.define(:version => 20120215023943) do

create_table "activity_streams", :force => true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -390,6 +390,14 @@
t.datetime "updated_at"
end

create_table "phone_numbers", :force => true do |t|
t.string "label"
t.string "number"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "photos", :force => true do |t|
t.integer "user_id"
t.string "native_photo_id"
Expand Down

0 comments on commit 710800c

Please sign in to comment.