現在、rubyにてユーザーの画像をuser.prof_imgというカラムに格納しております。
そして行いたいことはユーザーがprof_imgを何も入れていない場合はこちらが用意した画像を表示させておくということです。
ruby
1<div class="prof_block"> 2 <% if current_user.prof_img.nil? %> 3nil 4 <%= image_tag ('Gravatar-icon.png') %> 5 <% else %> 6notnil 7 <%= image_tag current_user.prof_img %> 8 <% end %> 9</div>
現在のユーザーのデータは以下です。
#<User id: 3, email: "sample@gmail.com", created_at: "2017-11-21 00:02:21", updated_at: "2017-11-21 00:02:21", provider: nil, uid: nil, username: "sample", prof_img: nil, creator_buyer: nil>]>
しかし表示されるのはnotnilであり画像は表示がされないです。
画像の有無の判断として
ruby
1<div class="prof_block"> 2 <% if current_user.prof_img == nil %> 3nil 4 <%= image_tag ('Gravatar-icon.png') %> 5 <% else %> 6notnil 7 <%= image_tag current_user.prof_img %> 8 <% end %> 9</div>
なども試しましたがうまくいきませんでした。
理由がわかるかた、心当たりある方、ご質問、ご回答していただけますと幸いです。
何卒よろしくお願いします。
##追記
ruby
1<%= current_user.prof_img.inspect %>
を行うと、以下のように表示されました。
ruby
1#<ImageUploader:0x007ff8beb3a3a8 @model=#<User id: 3, email: "sample@gmail.com", created_at: "2017-11-21 00:02:21", updated_at: "2017-11-21 03:26:31", provider: nil, uid: nil, username: "sample", prof_img: nil, creator_buyer: nil>, @mounted_as=:prof_img>
回答1件
あなたの回答
tips
プレビュー