-
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.
Fixed and added some functionality with the FollowRelationship Model
- Added a follows and unfollow button - Added a counter for follows - Fixed countless spelling errors and mistakes
- Loading branch information
a2k11
committed
Oct 21, 2014
1 parent
ef738e4
commit 166ec25
Showing
11 changed files
with
104 additions
and
19 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,16 @@ | ||
class FollowsController < ApplicationController | ||
def create | ||
user = User.find_by(username: params[:id]) | ||
current_user.follow(user) | ||
|
||
redirect_to user | ||
end | ||
|
||
def destroy | ||
user = User.find_by(username: params[:id]) | ||
current_user.unfollow(user) | ||
|
||
redirect_to user | ||
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 |
---|---|---|
@@ -1,23 +1,23 @@ | ||
class ShoutsController < ApplicationController | ||
before_action :require_login | ||
|
||
def new | ||
@shout = Shout.new | ||
end | ||
|
||
def create | ||
@shout = current_user.shouts.new(shout_params) | ||
def new | ||
@shout = Shout.new | ||
end | ||
|
||
def create | ||
@shout = current_user.shouts.new(shout_params) | ||
|
||
if @shout.save | ||
redirect_to dashboard_path | ||
else | ||
render :new | ||
if @shout.save | ||
redirect_to dashboard_path | ||
else | ||
render :new | ||
end | ||
end | ||
end | ||
|
||
|
||
private | ||
def shout_params | ||
params.require(:shout).permit(:content) | ||
end | ||
def shout_params | ||
params.require(:shout).permit(:content, :username) | ||
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,4 @@ | ||
class FollowRelationship < ActiveRecord::Base | ||
belongs_to :followed_user, class_name: "User" | ||
belongs_to :follower, class_name: "User" | ||
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class Shout < ActiveRecord::Base | ||
|
||
delegate :username, to: :user | ||
belongs_to :user | ||
|
||
validates :content, presence: true | ||
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
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,15 @@ | ||
<h1>This is <%= @user.username.capitalize %>'s page.</h1> | ||
<br> | ||
<% unless @user.followers.include? current_user %> | ||
<%= button_to "follow" , follows_user_path(@user.username) %> | ||
<% else %> | ||
<%= button_to "unfollow" , follows_user_path(@user.username), method: :delete %> | ||
<% end %> | ||
<br> | ||
<%= @user.followers.count %> | ||
<br> | ||
<% @user.shouts.each do |shout| %> | ||
<div> | ||
<%= shout.content %> | ||
</div> | ||
<% 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,10 @@ | ||
class CreateFollowRelationships < ActiveRecord::Migration | ||
def change | ||
create_table :follow_relationships do |t| | ||
t.references :follower | ||
t.references :followed_user | ||
|
||
t.timestamps | ||
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