回答編集履歴
2
テキスト修正
answer
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
こんにちは。
|
2
2
|
|
3
|
+
あくまで「自分ならこうするかも」という一例ですが、
|
3
|
-
|
4
|
+
@a_matsuda さん作の [ActiveDecorator](https://github.com/amatsuda/active_decorator) を使って、
|
4
5
|
`User` のデコレータ `module UserDecorator` を作り、そこに、
|
5
6
|
|
6
7
|
```ruby
|
1
テキスト修正
answer
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
こんにちは。
|
2
2
|
|
3
|
-
あくまで「自分ならこうするかも」という一例ですが、@a_matsuda さんの
|
4
|
-
[
|
3
|
+
あくまで「自分ならこうするかも」という一例ですが、@a_matsuda さん作の [ActiveDecorator](https://github.com/amatsuda/active_decorator) を使って、
|
5
|
-
そこに、
|
4
|
+
`User` のデコレータ `module UserDecorator` を作り、そこに、
|
6
5
|
|
7
6
|
```ruby
|
8
|
-
def
|
7
|
+
def unread_notifications_count_string(zero='0')
|
9
8
|
count = notifications.where(read: false).count
|
10
9
|
count != 0 ? count.to_s : zero
|
11
10
|
end
|
@@ -17,7 +16,7 @@
|
|
17
16
|
<%= current_user.unread_ notifications_count_string('') %>
|
18
17
|
```
|
19
18
|
|
20
|
-
とするか、コントローラのほうで
|
19
|
+
とするか、コントローラのアクションのほうで、
|
21
20
|
|
22
21
|
```ruby
|
23
22
|
@unread_ notifications_count_string = ・・・ # 0 のときは空文字列が入るようにする。
|
@@ -29,6 +28,7 @@
|
|
29
28
|
```
|
30
29
|
|
31
30
|
とするか、このどちらかを考えます。
|
31
|
+
|
32
32
|
どちらがいいかは、この箇所以外で、このような場合どのように解決しているかの
|
33
33
|
プロジェクトの流儀というか慣習があると思うので、それに合わせます。
|
34
34
|
|