Skip to content

Commit

Permalink
ランキング機能(カウントのみ、表示はまだ)
Browse files Browse the repository at this point in the history
#What
・profilesテーブルにpv_countカラム 追加
・usersコントローラーで、users/showにアクセスするたびにpv_countが1つずつ増えるように処理を記載
・リンクがつき次第、カウントが正常に確認できるか再確認する必要あり。
・リロードしてもpv数+1

#Why
・pv数を保存するため
・gem(impressionist)は、rails5系から更新されていないため、使うのをやめました。
charlotte-ruby/impressionist#279
  • Loading branch information
ShuheiOhno committed Oct 18, 2020
1 parent fa045b2 commit d756a98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def index
def show
@user = User.find(params[:id])
@profile = @user.profile
@profile.pv_count += 1
@profile.update(pv_count: @profile.pv_count)
# タグ全部取ってきます
@tag_list = Tag.all
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20201018101705_add_pv_count_to_profiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPvCountToProfiles < ActiveRecord::Migration[6.0]
def change
# null:falseで初期値0
add_column :profiles, :pv_count, :integer, null: false
end
end
7 changes: 3 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_10_11_124509) do
ActiveRecord::Schema.define(version: 2020_10_18_101705) do

create_table "cards", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id"
Expand Down Expand Up @@ -114,12 +114,13 @@
t.string "twitter"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "color"
t.string "sub_image"
t.string "catch_copy"
t.string "avatar_title"
t.string "avatar_catch_copy"
t.text "avatar_about"
t.string "color"
t.integer "pv_count", null: false
t.index ["user_id"], name: "index_profiles_on_user_id"
end

Expand All @@ -132,15 +133,13 @@
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "name", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "nickname", null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["name"], name: "index_users_on_name", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
integrity sha512-725AQupWJZ8ba0jbKceeFblZTY90McUBWMwHhkFQ9q1zKPJ95GUktljFcgcsIVwRnTnRKlcYzfiNImg5G9m6ZQ==

"@babel/core@^7.7.2":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.1.tgz#980b115a05929ef3ce1b6af9bf50e5a5cf668667"
integrity sha512-6bGmltqzIJrinwRRdczQsMhruSi9Sqty9Te+/5hudn4Izx/JYRhW1QELpR+CIL0gC/c9A7WroH6FmkDGxmWx3w==
version "7.12.3"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.3.tgz#1b436884e1e3bff6fb1328dc02b208759de92ad8"
integrity sha512-0qXcZYKZp3/6N2jKYVxZv0aNCsxTSVCiK72DTiTYZAu7sjg73W0/aynWjMbiGd87EQL4WyA8reiJVh92AVla9g==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/generator" "^7.12.1"
"@babel/helper-module-transforms" "^7.12.1"
"@babel/helpers" "^7.12.1"
"@babel/parser" "^7.12.1"
"@babel/parser" "^7.12.3"
"@babel/template" "^7.10.4"
"@babel/traverse" "^7.12.1"
"@babel/types" "^7.12.1"
Expand Down Expand Up @@ -228,9 +228,9 @@
integrity sha512-YpJabsXlJVWP0USHjnC/AQDTLlZERbON577YUVO/wLpqyj6HAtVYnWaQaN0iUN+1/tWn3c+uKKXjRut5115Y2A==

"@babel/helper-wrap-function@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.10.4.tgz#8a6f701eab0ff39f765b5a1cfef409990e624b87"
integrity sha512-6py45WvEF0MhiLrdxtRjKjufwLL1/ob2qDJgg5JgNdojBAZSAKnAjkyOCNug6n+OBl4VW76XjvgSFTdaMcW0Ug==
version "7.12.3"
resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.12.3.tgz#3332339fc4d1fbbf1c27d7958c27d34708e990d9"
integrity sha512-Cvb8IuJDln3rs6tzjW3Y8UeelAOdnpB8xtQ4sme2MSZ9wOxrbThporC0y/EtE16VAtoyEfLM404Xr1e0OOp+ow==
dependencies:
"@babel/helper-function-name" "^7.10.4"
"@babel/template" "^7.10.4"
Expand All @@ -255,10 +255,10 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/parser@^7.10.4", "@babel/parser@^7.12.1":
version "7.12.1"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.1.tgz#dc03f543a0ed51396d4081463df66ecb3a2efa53"
integrity sha512-xjZsx0sBjb6J2+QkoHI69UeD2EWbsyUW0WyZKOoJ9sBrQLxfOApWEefR9dIVOYJVj97VRXnLKLDvnn3dPDNgww==
"@babel/parser@^7.10.4", "@babel/parser@^7.12.1", "@babel/parser@^7.12.3":
version "7.12.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.3.tgz#a305415ebe7a6c7023b40b5122a0662d928334cd"
integrity sha512-kFsOS0IbsuhO5ojF8Hc8z/8vEIOkylVBrjiZUbLTE3XFe0Qi+uu6HjzQixkFaqr0ZPAMZcBVxEwmsnsLPZ2Xsw==

"@babel/plugin-proposal-async-generator-functions@^7.12.1":
version "7.12.1"
Expand Down Expand Up @@ -926,9 +926,9 @@
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/node@*":
version "14.11.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.8.tgz#fe2012f2355e4ce08bca44aeb3abbb21cf88d33f"
integrity sha512-KPcKqKm5UKDkaYPTuXSx8wEP7vE9GnuaXIZKijwRYcePpZFDVuy2a57LarFKiORbHOuTOOwYzxVxcUzsh2P2Pw==
version "14.11.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.10.tgz#8c102aba13bf5253f35146affbf8b26275069bef"
integrity sha512-yV1nWZPlMFpoXyoknm4S56y2nlTAuFYaJuQtYRAOU7xA/FJ9RY0Xm7QOkaYMMmr8ESdHIuUb6oQgR/0+2NqlyA==

"@types/parse-json@^4.0.0":
version "4.0.0"
Expand Down Expand Up @@ -2629,9 +2629,9 @@ [email protected]:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.571:
version "1.3.581"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.581.tgz#7f796fe92cdc18f5013769dc6f45f4536315a183"
integrity sha512-ALORbI23YkYJoVJWusSdmTq8vXH3TLFzniILE47uZkZOim135ZhoTCM7QlIuvmK78As5kLdANfy7kDIQvJ+iPw==
version "1.3.582"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.582.tgz#1adfac5affce84d85b3d7b3dfbc4ade293a6ffc4"
integrity sha512-0nCJ7cSqnkMC+kUuPs0YgklFHraWGl/xHqtZWWtOeVtyi+YqkoAOMGuZQad43DscXCQI/yizcTa3u6B5r+BLww==

elliptic@^6.5.3:
version "6.5.3"
Expand Down Expand Up @@ -2678,9 +2678,9 @@ enhanced-resolve@^4.1.1, enhanced-resolve@^4.3.0:
tapable "^1.0.0"

entities@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
integrity sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==
version "2.1.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.1.0.tgz#992d3129cf7df6870b96c57858c249a120f8b8b5"
integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==

errno@^0.1.3, errno@~0.1.7:
version "0.1.7"
Expand Down

0 comments on commit d756a98

Please sign in to comment.