Wednesday, 25 November 2015

Determine if asset exists?

Determine if asset exists?

 Rails.application.assets.find_asset("cards/header.png")
 => #<Sprockets::Asset:1d346d0 "file:///home/saritha/sites/new_app/app/assets/images/cards/header.png?type=image/png&id=d571d3707e9e08e6527f5c6049742fc7a13672b43ebbcffe625c8986d31c3759">

Rails.application.assets.find_asset 'notthere.png'
 => nil

Rails.application.assets.find_asset("cards/header.png").present?
=> true

Rails.application.assets.find_asset("cards/notthere.png").present?
=> false

No comments:

Post a Comment