Commit b1314b9

mo khan <mo@mokhan.ca>
2013-06-22 16:12:07
associate needs to user"
1 parent 133da75
Changed files (3)
app/models/need.rb
@@ -1,3 +1,4 @@
 class Need < ActiveRecord::Base
+  belongs_to :user
   attr_accessible :description, :user_id
 end
app/models/user.rb
@@ -2,10 +2,10 @@ 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
+  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
+  has_many :needs
 end
app/views/needs/index.html.erb
@@ -1,21 +1,15 @@
-<h1>Listing needs</h1>
+<h1>Needs</h1>
 
-<table>
+<table class="table">
   <tr>
     <th>Description</th>
-    <th>User</th>
-    <th></th>
-    <th></th>
-    <th></th>
+    <th>Person</th>
   </tr>
 
 <% @needs.each do |need| %>
   <tr>
     <td><%= need.description %></td>
-    <td><%= need.user_id %></td>
-    <td><%= link_to 'Show', need %></td>
-    <td><%= link_to 'Edit', edit_need_path(need) %></td>
-    <td><%= link_to 'Destroy', need, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+    <td><%= need.user.email %></td>
   </tr>
 <% end %>
 </table>