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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d604abaf77a9180b5a024d4b8547822ed95d753c44725891f91d5f67bf09cc24
4
- data.tar.gz: 90a4dcca82463b218fcda903e16a0f7a3a0c4716637aecdc9b5d3be5cd8a2cb1
3
+ metadata.gz: c9a7de9c9491bbb1ef648bb7d64cb3d596cc29803498e1d15180317a5a03a0e6
4
+ data.tar.gz: 6cb3d91654650cdef620521f02e643a87a62157b1912b099a9dd221fe5553568
5
5
  SHA512:
6
- metadata.gz: 95783e0b3c87e8dc35b442db77887a1210e3678ed802d295701627ac257bb3d641da740f6c7f70f0571175a3cf28c160facd5e2da8197e8de6eb8e863119c087
7
- data.tar.gz: 1f953cd9e5ee150bb378079fb6db297031a8fe470dbdc7fed03219dac4d9fb2e92ea0170194b7a6e9f336a1dc5636b9bc97f46ba50369b51b700ed826718c545
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: User.find_by(name: params[:username]))
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: User.find_by(name: params[:username])).destroy
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
@@ -5,6 +5,8 @@ class ProfilesController < ApplicationController
5
5
  # GET /users/1.json
6
6
  def show
7
7
  @user = User.find_by(name: params[:username])
8
+ @observes = @user.observe_users
9
+ @observed = @user.observed_users
8
10
  end
9
11
 
10
12
  # GET /users/1/edit
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)
@@ -0,0 +1,11 @@
1
+ h2
2
+ = @user.screen_name
3
+ | &nbsp;
4
+ small= '@' + @user.name
5
+
6
+ ul
7
+ - @observes.each do |user|
8
+ li= link_to '/' + user.name
9
+ = user.screen_name
10
+ | &nbsp;
11
+ small= '@' + user.name
@@ -0,0 +1,11 @@
1
+ h2
2
+ = @user.screen_name
3
+ | &nbsp;
4
+ small= '@' + @user.name
5
+
6
+ ul
7
+ - @observes.each do |user|
8
+ li= link_to '/' + user.name
9
+ = user.screen_name
10
+ | &nbsp;
11
+ small= '@' + user.name
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Xwitter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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