回答編集履歴

1

コード修正

2016/03/13 08:37

投稿

honkimi
honkimi

スコア10

test CHANGED
@@ -1,4 +1,4 @@
1
- `try` を使えば解決すると思いますが、いかがでしょう?
1
+ 自分ならこんな感じですかね。余談ですが `image_for` はかなり汎用的な名前なのであまりいいヘルパメソッド名ではないように思います
2
2
 
3
3
 
4
4
 
@@ -6,17 +6,11 @@
6
6
 
7
7
  module UsersHelper
8
8
 
9
- def image_for(user)
9
+ def user_profile_img(user)
10
10
 
11
- if user.try(:image)
11
+ path = user.try(:image) ? "/user_images/#{user.image}" : "kikirara.png"
12
12
 
13
- image_tag "/user_images/#{user.image}", class: "profile_img"
14
-
15
- else
16
-
17
- image_tag "kikirara.png", class: "profile_img"
13
+ image_tag path, class: "profile_img"
18
-
19
- end
20
14
 
21
15
  end
22
16