質問するログイン新規登録

回答編集履歴

1

コード修正

2016/03/13 08:37

投稿

honkimi
honkimi

スコア10

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