Commit ec07cc9

mo khan <mo@mokhan.ca>
2013-06-22 17:13:15
add name to user model
1 parent b00345a
app/helpers/application_helper.rb
@@ -1,6 +1,6 @@
 module ApplicationHelper
   def gravatar_for(user, options = { size: 80 })
     gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
-    image_tag("https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{options[:size]}&d=mm", alt: user.email, class: 'gravatar')
+    image_tag("https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{options[:size]}&d=mm", alt: user.name, class: 'gravatar')
   end
 end
app/models/user.rb
@@ -1,11 +1,6 @@
 class User < ActiveRecord::Base
-  # Include default devise modules. Others available are:
-  # :token_authenticatable, :confirmable,
-  # :lockable, :timeoutable and :omniauthable
   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
 
-  # Setup accessible (or protected) attributes for your model
-  attr_accessible :email, :password, :password_confirmation, :remember_me
-  # attr_accessible :title, :body
+  attr_accessible :name, :email, :password, :password_confirmation, :remember_me
   has_many :needs
 end
app/views/devise/registrations/edit.html.erb
@@ -3,8 +3,11 @@
 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
   <%= devise_error_messages! %>
 
+  <div><%= f.label :name %><br />
+  <%= f.text_field :name, :autofocus => true %></div>
+
   <div><%= f.label :email %><br />
-  <%= f.email_field :email, :autofocus => true %></div>
+  <%= f.email_field :email %></div>
 
   <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
     <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
app/views/devise/registrations/new.html.erb
@@ -3,8 +3,11 @@
 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
   <%= devise_error_messages! %>
 
+  <div><%= f.label :name %><br />
+  <%= f.text_field :name, :autofocus => true %></div>
+
   <div><%= f.label :email %><br />
-  <%= f.email_field :email, :autofocus => true %></div>
+  <%= f.email_field :email %></div>
 
   <div><%= f.label :password %><br />
   <%= f.password_field :password %></div>
app/views/layouts/_header.html.erb
@@ -11,9 +11,9 @@
       <ul class="nav pull-right">
         <% if user_signed_in? %>
           <li class="dropdown">
-            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><%= current_user.email %><b class="caret"></b></a>
+            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><%= current_user.email %> <i class="icon-gear"></i><b class="caret"></b></a>
             <ul class="dropdown-menu">
-              <li> <%= link_to "I Need", needs_path %> </li>
+              <li> <%= link_to "Settings", edit_user_registration_path %> </li>
               <li class="divider"></li>
               <li><%= link_to('Logout', destroy_user_session_path, :method => :delete) %></li>
             </ul>
app/views/layouts/application.html.erb
@@ -6,6 +6,8 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
     <title>YYC Rebuild</title>
     <%= stylesheet_link_tag :application %>
+    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
+    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
     <%= yield :head %>
     <%= csrf_meta_tags %>
   </head>
db/migrate/20130622170818_add_name_to_users.rb
@@ -0,0 +1,5 @@
+class AddNameToUsers < ActiveRecord::Migration
+  def change
+    add_column :users, :name, :string
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130622160401) do
+ActiveRecord::Schema.define(:version => 20130622170818) do
 
   create_table "needs", :force => true do |t|
     t.text     "description"
@@ -33,6 +33,7 @@ ActiveRecord::Schema.define(:version => 20130622160401) do
     t.string   "last_sign_in_ip"
     t.datetime "created_at",                             :null => false
     t.datetime "updated_at",                             :null => false
+    t.string   "name"
   end
 
   add_index "users", ["email"], :name => "index_users_on_email", :unique => true