Displaying images from this controllers code


Im pretty new to rails so please excuse me if this is a trivial question
to most of you :slight_smile:

Im making use of the following code that I came accross which allows me
to go and feed amazons alexa service a url and it returns a thumbnaill.

class AmazonController < ApplicationController

layout ‘default’
def index
require ‘cgi’
require ‘openssl’
require ‘base64’
require ‘open-uri’

access_id = 'XXXXX'
secret_id = 'XXXXXXXXXX'

source_url = 'google.com'

timestamp = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
sig =

secret_id, ‘Thumbnail’ + timestamp)).strip

url =

http://ast.amazonaws.com/Xino?Action=Thumbnail&AWSAccessKeyId=” +
url << “&Signature=” + CGI.escape(sig)
url << “&Timestamp=” + CGI.escape(timestamp)
url << “&Url=” + source_url

  doc = open(url).read
  puts "Could not access AWS"

m = doc.match(/\<aws:thumbnail[^\>]+exists=\"true\"\>(.+?)\<\//i)

if m && m[1]
  thumb_url = m[1]
  thumb_url.gsub!(/\&amp;/, '&')
  File.open("#{source_url}.jpg", "w") { |f| f.write

open(thumb_url).read }
puts “Saved to #{source_url}.jpg”
elsif m && m.match(/exists=“false”/)
puts “No thumbnail for #{source_url}”
puts “Error”


This all works fine when i fire it off as a ruby script and places the
thumbnail in the same directory as the ruby script. what I want now
though is to bring the same code to rails. I have placed it in a
controller as you can see above and I would like now to display these
thumbnails on the front end view.

How does one access this information and bring it up on the front end? I
dont entirely understand how the image is written to disk which could be
part of the problem.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs