From 56450cf31916fbf13b77451a258fbb9612899723 Mon Sep 17 00:00:00 2001 From: Will Bradley Date: Sat, 8 Feb 2014 21:06:07 -0700 Subject: [PATCH] Adding postal code to users --- app/models/user.rb | 4 +++- app/views/devise/registrations/_user.html.erb | 9 +++++++-- app/views/users/_form.html.erb | 4 ++++ db/migrate/20140209025344_add_postal_code_to_users.rb | 5 +++++ db/schema.rb | 3 ++- test/fixtures/users.yml | 10 +++------- 6 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20140209025344_add_postal_code_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 1180736..90586b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ class User < ActiveRecord::Base :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model - attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :member, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level, :certifications, :hidden, :marketing_source, :payee, :accountant, :exit_reason, :twitter_url, :facebook_url, :github_url, :website_url, :email_visible, :phone_visible #TODO: make admin/instructor/member/etc not accessible + attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :member, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level, :certifications, :hidden, :marketing_source, :payee, :accountant, :exit_reason, :twitter_url, :facebook_url, :github_url, :website_url, :email_visible, :phone_visible, :postal_code #TODO: make admin/instructor/member/etc not accessible has_many :cards has_many :user_certifications @@ -19,6 +19,8 @@ class User < ActiveRecord::Base validates_format_of [:twitter_url, :facebook_url, :github_url, :website_url], :with => URI::regexp(%w(http https)), :allow_blank => true + validates_presence_of :postal_code + after_create :send_new_user_email def absorb_user(user_to_absorb) diff --git a/app/views/devise/registrations/_user.html.erb b/app/views/devise/registrations/_user.html.erb index be950b3..a771dd3 100644 --- a/app/views/devise/registrations/_user.html.erb +++ b/app/views/devise/registrations/_user.html.erb @@ -35,6 +35,11 @@ Thanks again, and happy hacking!

<%= f.label :phone_visible, "Show Phone to All Members?" %> +
+ <%= f.label :postal_code, "Residential Postal Code" %>
+ <%= f.text_field :postal_code %> (we'd like to know where you're commuting from!) +
+
<%= f.label :twitter_url %> <%= f.text_field :twitter_url, :placeholder => "https://twitter.com/heatsynclabs" %>
@@ -71,13 +76,13 @@ Thanks again, and happy hacking!

<%= f.text_area :marketing_source %>
-
<%= f.label :password %><% if params[:action]!='new' %> (Only if you want to change your password)<% end %>
+
<%= f.label :password %><% unless ['new','create'].include?(params[:action]) %> (Only if you want to change your password)<% end %>
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
- <% if params[:action]!='new' %> + <% unless ['new','create'].include?(params[:action]) %>
<%= f.label :current_password, "Type Your Current Password" %> (For your account's security)
<%= f.password_field :current_password %>
<% end %> diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 963bfb9..ac31cdc 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -46,6 +46,10 @@ <%= f.check_box :phone_visible %> <%= f.label :phone_visible, "Show Phone to All Members?" %>
+
+ <%= f.label :postal_code, "Residential Postal Code" %>
+ <%= f.text_field :postal_code %> (we'd like to know where you're commuting from!) +
<%= f.label :twitter_url %> <%= f.text_field :twitter_url, :placeholder => "https://twitter.com/heatsynclabs" %>
diff --git a/db/migrate/20140209025344_add_postal_code_to_users.rb b/db/migrate/20140209025344_add_postal_code_to_users.rb new file mode 100644 index 0000000..72b8b02 --- /dev/null +++ b/db/migrate/20140209025344_add_postal_code_to_users.rb @@ -0,0 +1,5 @@ +class AddPostalCodeToUsers < ActiveRecord::Migration + def change + add_column :users, :postal_code, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9d0fb6d..d5522db 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130928112252) do +ActiveRecord::Schema.define(:version => 20140209025344) do create_table "cards", :force => true do |t| t.string "card_number" @@ -174,6 +174,7 @@ ActiveRecord::Schema.define(:version => 20130928112252) do t.string "website_url" t.boolean "email_visible" t.boolean "phone_visible" + t.string "postal_code" end add_index "users", ["email"], :name => "index_users_on_email", :unique => true diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 96d5bf5..04027e1 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -2,12 +2,8 @@ one: name: MyString - card_id: 1 - card_number: MyString - card_permissions: 1 + postal_code: 12345 two: - name: MyString - card_id: 1 - card_number: MyString - card_permissions: 1 + name: MyString2 + postal_code: 23456