Xwitter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Schemafile +20 -10
- data/app/controllers/follows_controller.rb +13 -0
- data/app/controllers/messages_controller.rb +7 -1
- data/app/models/observe.rb +4 -0
- data/app/models/user.rb +8 -0
- data/app/views/messages/_index.html.slim +1 -1
- data/app/views/messages/index.html.slim +1 -12
- data/app/views/profiles/show.html.slim +8 -2
- data/config/routes.rb +2 -0
- data/lib/Xwitter/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d604abaf77a9180b5a024d4b8547822ed95d753c44725891f91d5f67bf09cc24
|
4
|
+
data.tar.gz: 90a4dcca82463b218fcda903e16a0f7a3a0c4716637aecdc9b5d3be5cd8a2cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95783e0b3c87e8dc35b442db77887a1210e3678ed802d295701627ac257bb3d641da740f6c7f70f0571175a3cf28c160facd5e2da8197e8de6eb8e863119c087
|
7
|
+
data.tar.gz: 1f953cd9e5ee150bb378079fb6db297031a8fe470dbdc7fed03219dac4d9fb2e92ea0170194b7a6e9f336a1dc5636b9bc97f46ba50369b51b700ed826718c545
|
data/Schemafile
CHANGED
@@ -1,23 +1,34 @@
|
|
1
1
|
# Export Schema
|
2
|
-
create_table
|
3
|
-
t.string
|
4
|
-
t.string
|
5
|
-
t.string
|
6
|
-
t.string
|
7
|
-
t.string
|
8
|
-
t.boolean
|
9
|
-
t.datetime
|
10
|
-
t.datetime
|
2
|
+
create_table "users" do |t|
|
3
|
+
t.string "email", null: false
|
4
|
+
t.string "name"
|
5
|
+
t.string "screen_name"
|
6
|
+
t.string "encrypted_password", null: false
|
7
|
+
t.string "reset_password_token"
|
8
|
+
t.boolean "public", null: false, default: true
|
9
|
+
t.datetime "reset_password_sent_at"
|
10
|
+
t.datetime "remember_created_at"
|
11
11
|
t.timestamps null: false
|
12
12
|
t.index ["name"], unique: true
|
13
13
|
end
|
14
14
|
|
15
|
+
create_table "observes", force: :cascade do |t|
|
16
|
+
t.bigint "from_user_id", null: false
|
17
|
+
t.bigint "to_user_id", null: false
|
18
|
+
t.timestamps null: false
|
19
|
+
t.index ["from_user_id", "to_user_id"], unique: true
|
20
|
+
t.index ["to_user_id", "from_user_id"], unique: true
|
21
|
+
end
|
22
|
+
add_foreign_key "observes", "users", column: "from_user_id"
|
23
|
+
add_foreign_key "observes", "users", column: "to_user_id", name: "observe_to_user_fk"
|
24
|
+
|
15
25
|
create_table "messages", force: :cascade do |t|
|
16
26
|
t.bigint "user_id", null: false
|
17
27
|
t.text "text", null: false
|
18
28
|
t.datetime "created_at", null: false
|
19
29
|
t.index ["user_id"]
|
20
30
|
end
|
31
|
+
add_foreign_key "messages", "users"
|
21
32
|
|
22
33
|
create_table "likes", force: :cascade do |t|
|
23
34
|
t.bigint "user_id", null: false
|
@@ -33,7 +44,6 @@ create_table "shares", force: :cascade do |t|
|
|
33
44
|
t.index ["user_id", "message_id"], unique: true
|
34
45
|
end
|
35
46
|
|
36
|
-
add_foreign_key "messages", "users"
|
37
47
|
add_foreign_key "likes", "users"
|
38
48
|
add_foreign_key "likes", "messages"
|
39
49
|
add_foreign_key "shares", "users"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class FollowsController < ApplicationController
|
2
|
+
# POST /:username/follow
|
3
|
+
def create
|
4
|
+
Observe.create!(from_user: current_user, to_user: User.find_by(name: params[:username]))
|
5
|
+
redirect_to "/" + params[:username]
|
6
|
+
end
|
7
|
+
|
8
|
+
# DELETE /:username/follow
|
9
|
+
def destroy
|
10
|
+
Observe.find_by(from_user: current_user, to_user: User.find_by(name: params[:username])).destroy
|
11
|
+
redirect_to "/" + params[:username]
|
12
|
+
end
|
13
|
+
end
|
@@ -8,7 +8,13 @@ class MessagesController < ApplicationController
|
|
8
8
|
redirect_to edit_profile_url
|
9
9
|
return
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
if user_signed_in?
|
13
|
+
user_ids = current_user.observe_users.pluck(:id) + [current_user.id]
|
14
|
+
@messages = Message.where(user_id: user_ids)
|
15
|
+
else
|
16
|
+
@messages = Message.all
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
# GET /messages/1
|
data/app/models/user.rb
CHANGED
@@ -3,4 +3,12 @@ class User < ApplicationRecord
|
|
3
3
|
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
4
4
|
devise :database_authenticatable, :registerable,
|
5
5
|
:recoverable, :rememberable, :validatable
|
6
|
+
|
7
|
+
has_many :observes, foreign_key: "from_user_id", class_name: "Observe"
|
8
|
+
has_many :observe_users, through: :observes, source: "to_user"
|
9
|
+
has_many :observed, foreign_key: "to_user_id", class_name: "Observe"
|
10
|
+
|
11
|
+
def follow?(user)
|
12
|
+
observe_users.include?(user)
|
13
|
+
end
|
6
14
|
end
|
@@ -6,15 +6,4 @@ h1
|
|
6
6
|
= link_to 'Sign in', new_user_session_path, class: 'btn btn-primary'
|
7
7
|
= link_to 'Sign up', new_user_registration_path, class: 'btn btn-default'
|
8
8
|
|
9
|
-
|
10
|
-
div
|
11
|
-
p
|
12
|
-
= message.user.screen_name
|
13
|
-
|
|
14
|
-
= link_to '@' + message.user.name, '/' + message.user.name
|
15
|
-
|
16
|
-
p= message.text
|
17
|
-
p= l message.created_at
|
18
|
-
- if user_signed_in? && message.user == current_user
|
19
|
-
.oi.oi-trash
|
20
|
-
= link_to 'Destroy', message, data: { confirm: 'Are you sure?' }, method: :delete
|
9
|
+
= render 'index', messages: @messages
|
@@ -2,7 +2,13 @@ h2
|
|
2
2
|
= @user.screen_name
|
3
3
|
|
|
4
4
|
small= '@' + @user.name
|
5
|
-
- if
|
6
|
-
|
5
|
+
- if user_signed_in?
|
6
|
+
|
|
7
|
+
- if @user == current_user
|
8
|
+
= link_to 'Edit', edit_profile_path, class: 'btn'
|
9
|
+
- elsif current_user.follow?(@user)
|
10
|
+
= link_to 'Unfollow', follow_path, class: 'btn btn-warning', method: :delete
|
11
|
+
- else
|
12
|
+
= link_to 'Follow', follow_path, class: 'btn btn-primary', method: :post
|
7
13
|
|
8
14
|
= render 'messages/index', messages: Message.where(user: @user)
|
data/config/routes.rb
CHANGED
data/lib/Xwitter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Xwitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- myun2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- app/channels/application_cable/connection.rb
|
72
72
|
- app/controllers/application_controller.rb
|
73
73
|
- app/controllers/concerns/.keep
|
74
|
+
- app/controllers/follows_controller.rb
|
74
75
|
- app/controllers/messages_controller.rb
|
75
76
|
- app/controllers/profiles_controller.rb
|
76
77
|
- app/helpers/application_helper.rb
|
@@ -87,6 +88,7 @@ files:
|
|
87
88
|
- app/models/application_record.rb
|
88
89
|
- app/models/concerns/.keep
|
89
90
|
- app/models/message.rb
|
91
|
+
- app/models/observe.rb
|
90
92
|
- app/models/user.rb
|
91
93
|
- app/views/layouts/application.html.slim
|
92
94
|
- app/views/layouts/mailer.html.erb
|