How to check if image exists in Rails?

前端 未结 4 1841
再見小時候
再見小時候 2021-01-11 12:39
<%= image_tag(\"/images/users/user_\" + @user_id.to_s + \".png\") %>

How do you check to see if there is such an image, and if not, then disp

4条回答
  •  甜味超标
    2021-01-11 13:26

    For Rails 5 the one that worked for me is

    ActionController::Base.helpers.resolve_asset_path("logos/smthg.png")

    returns nil if the asset is absent and path_of_the_asset if present

提交回复
热议问题