Xwitter 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/follows_controller.rb +20 -2
- data/app/controllers/profiles_controller.rb +2 -0
- data/app/models/user.rb +1 -0
- data/app/views/follows/followed.html.slim +11 -0
- data/app/views/follows/index.html.slim +11 -0
- data/app/views/profiles/show.html.slim +6 -0
- data/config/routes.rb +2 -0
- data/lib/Xwitter/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9a7de9c9491bbb1ef648bb7d64cb3d596cc29803498e1d15180317a5a03a0e6
|
4
|
+
data.tar.gz: 6cb3d91654650cdef620521f02e643a87a62157b1912b099a9dd221fe5553568
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21f27e91e3672305b8b7a777e3b49bea0a20581eb7436967b9014a2c5dc9dbee99529384483f0d2b98b76cfb954010439578d7171913cfac6d47595f17852db5
|
7
|
+
data.tar.gz: 624365d80d73c50c9e1f159fd6474ba175a2c5559fad1d6bef6ead1a9332e5912e66b4a25d40aaf1b2c374eaa37b77b4e715be0814602ddaa818a169efc552c3
|
@@ -1,13 +1,31 @@
|
|
1
1
|
class FollowsController < ApplicationController
|
2
|
+
before_action :set_user
|
3
|
+
|
4
|
+
# GET /:username/follows
|
5
|
+
def index
|
6
|
+
@observes = @user.observe_users
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /:username/followed
|
10
|
+
def followed
|
11
|
+
@observes = @user.observed_users
|
12
|
+
end
|
13
|
+
|
2
14
|
# POST /:username/follow
|
3
15
|
def create
|
4
|
-
Observe.create!(from_user: current_user, to_user:
|
16
|
+
Observe.create!(from_user: current_user, to_user: @user)
|
5
17
|
redirect_to "/" + params[:username]
|
6
18
|
end
|
7
19
|
|
8
20
|
# DELETE /:username/follow
|
9
21
|
def destroy
|
10
|
-
Observe.find_by(from_user: current_user, to_user:
|
22
|
+
Observe.find_by(from_user: current_user, to_user: @user).destroy
|
11
23
|
redirect_to "/" + params[:username]
|
12
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def set_user
|
29
|
+
@user = User.find_by(name: params[:username])
|
30
|
+
end
|
13
31
|
end
|
data/app/models/user.rb
CHANGED
@@ -7,6 +7,7 @@ class User < ApplicationRecord
|
|
7
7
|
has_many :observes, foreign_key: "from_user_id", class_name: "Observe"
|
8
8
|
has_many :observe_users, through: :observes, source: "to_user"
|
9
9
|
has_many :observed, foreign_key: "to_user_id", class_name: "Observe"
|
10
|
+
has_many :observed_users, through: :observed, source: "from_user"
|
10
11
|
|
11
12
|
def follow?(user)
|
12
13
|
observe_users.include?(user)
|
@@ -11,4 +11,10 @@ h2
|
|
11
11
|
- else
|
12
12
|
= link_to 'Follow', follow_path, class: 'btn btn-primary', method: :post
|
13
13
|
|
14
|
+
- if @user.follow?(current_user)
|
15
|
+
span.badge Followed you
|
16
|
+
|
17
|
+
= link_to "Followings: #{@observes.count}", follows_path(username: @user.name), class: 'btn'
|
18
|
+
= link_to "Followers: #{@observed.count}", followed_path(username: @user.name), class: 'btn'
|
19
|
+
|
14
20
|
= render 'messages/index', messages: Message.where(user: @user)
|
data/config/routes.rb
CHANGED
@@ -4,6 +4,8 @@ Rails.application.routes.draw do
|
|
4
4
|
devise_for :users
|
5
5
|
root 'messages#index'
|
6
6
|
get ':username', to: 'profiles#show'
|
7
|
+
get ':username/follows', to: 'follows#index', as: 'follows'
|
8
|
+
get ':username/followed', to: 'follows#followed', as: 'followed'
|
7
9
|
post ':username/follow', to: 'follows#create', as: 'follow'
|
8
10
|
delete ':username/follow', to: 'follows#destroy'
|
9
11
|
end
|
data/lib/Xwitter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Xwitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- myun2
|
@@ -90,6 +90,8 @@ files:
|
|
90
90
|
- app/models/message.rb
|
91
91
|
- app/models/observe.rb
|
92
92
|
- app/models/user.rb
|
93
|
+
- app/views/follows/followed.html.slim
|
94
|
+
- app/views/follows/index.html.slim
|
93
95
|
- app/views/layouts/application.html.slim
|
94
96
|
- app/views/layouts/mailer.html.erb
|
95
97
|
- app/views/layouts/mailer.text.erb
|