質問編集履歴
1
vagrant内でredisを立ち上げました。また、エラーの内容が変わりました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
https://yu-kyoto2720.hatenablog.com/entry/2018/10/31/165815
|
3
3
|
このサイトを参考にしてpvランキングサイトを作っています
|
4
|
+
|
5
|
+
下にスクリーンショットで貼っているエラーを解消したいです
|
6
|
+
|
7
|
+
https://qiita.com/hgsgtk/items/7e4990ad76ddaa6875e6
|
8
|
+
このサイトを参考にredisを立ち上げようとしていますが、sudo /etc/initを実行するとコマンドが見つかりませんと言われます
|
9
|
+
sudo /etc/init.d/redis start、redis-cliを実行すると下のようになります
|
10
|
+
```ここに言語を入力
|
11
|
+
[vagrant@localhost kadai7]$ sudo /etc/init.d/redis start
|
12
|
+
[vagrant@localhost kadai7]$ redis-cli
|
13
|
+
127.0.0.1:6379>
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
|
4
18
|
OSはmacで、vagrantのローカル環境です
|
5
|
-
エラーの解消方法がわかりません
|
6
19
|
|
20
|
+
http://0.0.0.0:3000/comments/11に接続した時のエラーです(解消したいエラー)
|
7
21
|
### 発生している問題・エラーメッセージ
|
8
|
-

|
9
23
|
|
10
24
|
|
11
25
|
### 該当のソースコード
|
@@ -93,13 +107,49 @@
|
|
93
107
|
|
94
108
|
def Comment.most_popular(limit: 4)
|
95
109
|
most_popular_ids = REDIS.zrevrangebyscore "comments", "+inf", 0, limit: [0, limit]
|
96
|
-
where(id: most_popular_ids).sort_by{ |
|
110
|
+
where(id: most_popular_ids).sort_by{ |comment| most_popular_ids.index(comment.id.to_s) }
|
97
111
|
end
|
98
112
|
end
|
99
113
|
|
100
114
|
```
|
115
|
+
show.html.erb
|
116
|
+
```
|
117
|
+
<div id="title">
|
118
|
+
<div>
|
119
|
+
<p><%= @comment.created_at %></p>
|
120
|
+
<%= @user.email %>
|
101
121
|
|
122
|
+
<h1><%= @comment.title %></h1>
|
123
|
+
</div>
|
124
|
+
</div>
|
125
|
+
<div id="article_wrap">
|
102
126
|
|
127
|
+
<div id="content"><%= @comment.content %>
|
128
|
+
</div>
|
129
|
+
<div class="clear"></div>
|
130
|
+
</div>
|
131
|
+
```
|
132
|
+
routes.rb
|
133
|
+
```
|
134
|
+
Rails.application.routes.draw do
|
135
|
+
|
136
|
+
devise_for :users
|
137
|
+
root 'comments#index'
|
138
|
+
get "comments/test" => "comments#test"
|
139
|
+
|
140
|
+
get 'comments/index'
|
141
|
+
get "comments/new" => "comments#new"
|
142
|
+
get "comments/:id" => "comments#show"
|
143
|
+
post 'comments/create' => 'comments#create'
|
144
|
+
get "comments/:id/edit" => "comments#edit"
|
145
|
+
post "comments/:id/update" => "comments#update"
|
146
|
+
post "comments/:id/destroy" => "comments#destroy"
|
147
|
+
|
148
|
+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
149
|
+
end
|
150
|
+
|
151
|
+
```
|
152
|
+
|
103
153
|
### 試したこと
|
104
154
|
|
105
155
|
redis、railsのサーバーの再起動
|