This repository has been archived by the owner on May 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added friendship model and confirmed_friends and requested_friends
- Loading branch information
Showing
10 changed files
with
169 additions
and
4 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 |
---|---|---|
@@ -0,0 1,18 @@ | ||
class FriendshipsController < ApplicationController | ||
|
||
def create | ||
@friendship = current_user.friendships.build(:friend_id => params[:friend_id]) | ||
if @friendship.save | ||
flash[:notice] = "Added friend." | ||
redirect_to root_url | ||
else | ||
flash[:notice] = "Unable to add friend." | ||
redirect_to root_url | ||
end | ||
end | ||
|
||
def index | ||
@friendships = current_user.friendships | ||
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,7 @@ | ||
class UsersController < ApplicationController | ||
|
||
def index | ||
@users = User.all | ||
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,8 @@ | ||
class Friendship < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :friend, :class_name => 'User' | ||
attr_accessible :friend, :user | ||
attr_accessible :friend_id, :user_id | ||
|
||
validates_presence_of :user, :friend | ||
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,65 @@ | ||
|
||
|
||
<h1>users</h1> | ||
|
||
<table class="table table-condensed"> | ||
<thead> | ||
<tr> | ||
<td>id</td> | ||
<td>email</td> | ||
</tr> | ||
</thead> | ||
|
||
<% @users.each do |user| %> | ||
<tr> | ||
<td><%= user.id %></td> | ||
<td><%= user.email %></td> | ||
<td><%= link_to "Friend", friendships_path(:friend_id => user), :method => :post %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<% if current_user.confirmed_friends.empty? %> | ||
No friends | ||
<% else %> | ||
<% if user_signed_in? %> | ||
<table class="table table-condensed"> | ||
<caption>Friends</caption> | ||
<thead> | ||
<tr> | ||
<td>friend id</td> | ||
<td>friend email</td> | ||
</tr> | ||
</thead> | ||
|
||
<% current_user.confirmed_friends.each do |friend| %> | ||
<tr> | ||
<td><%= friend.id %></td> | ||
<td><%= friend.email %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
|
||
<% if current_user.requested_friends.empty? %> | ||
No friend requests | ||
<% else %> | ||
<table class="table table-condensed"> | ||
<caption>Friend requests</caption> | ||
<thead> | ||
<tr> | ||
<td>requestor id</td> | ||
<td>requestor email</td> | ||
</tr> | ||
</thead> | ||
|
||
<% current_user.requested_friends.each do |requestor| %> | ||
<tr> | ||
<td><%= requestor.id %></td> | ||
<td><%= requestor.email %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<% 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
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 @@ | ||
class CreateFriendships < ActiveRecord::Migration | ||
def change | ||
create_table :friendships do |t| | ||
t.integer :user_id | ||
t.integer :friend_id | ||
end | ||
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
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 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | ||
|
||
one: | ||
user_id: 1 | ||
friend_id: 1 | ||
|
||
two: | ||
user_id: 1 | ||
friend_id: 1 |
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,7 @@ | ||
require 'test_helper' | ||
|
||
class FriendshipTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |