i'm using controller in rails 4 app serve images, want restrict access (similar this answer). images being served not stored in asset pipeline themselves, , programmatically generated. if image hasn't been generated yet, want show default / fallback image user. image stored other static assets.
so how can actual path image file give send_file
in controller? noted here asset_path , image_path
helpers not give local filesystem path, because of asset pipeline fingerprinting stuff, can't construct path myself either.
class thingscontroller before_filter :authorize_for_thing def show respond_to |format| format.all { if @thing.graph.file.present? file = @thing.graph_url() else ### serve static default image if file isn't there: ### file = file.join(rails.root, actioncontroller::base.helpers.asset_path("default_graph.png") ) end send_file file, :type=>"image/png", :disposition => 'inline' } end end end
but asset_path("default_graph.png") give of form:
assets/default_graph[possible-md5].png
when file lives elsewhere, , send_file needs literal path file.
rails.application.assets_manifest.assets[name]
Comments
Post a Comment