Forum: Ruby on Rails RE: Showing Images from a file store

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5190273ecab4b93b2d4e7529dcc1f7c6?d=identicon&s=25 unknown (Guest)
on 2006-04-13 03:42
(Received via mailing list)
Thanks a lot for the response. If you can post a working example, that
would be great.
Really appreciate it.
Silvy Mathews
6549e2022f07f561aa7eda4e555f2ca0?d=identicon&s=25 John Bresnik (Guest)
on 2006-04-14 00:24
(Received via mailing list)
Here's a [very] rough, but working example for a PDF..


class FileGrabberController < ApplicationController
	@@path = 'your/path'
	def get_file
		send_file @@path + 'a.pdf', :type => 'application/pdf'


<a href="file_grabber/get_file">pdf</a>

I know there's an inline option as well, i.e. for a JPG

:disposition => 'inline'

<img src="file_grabber/get_image"/>

or something like that - hope that helps..

30d8481c892d624b1b87d2e200b9248a?d=identicon&s=25 Silvy (Guest)
on 2006-04-14 01:04
(Received via mailing list)
Hi John,
That really worked. I did not knew that we could specify a controller
and the method name inside the view. Thanks a lot. Really appreciate

F0379e983ab499fac4d972494beab5c0?d=identicon&s=25 Brez! !! (brez)
on 2006-04-14 08:31

> That really worked.

good to hear..

>I did not knew that we could specify a controller
> name
> and the method name inside the view.

well what youre really specifying is a URL that is interpreted as that
method on that controller, i.e. the rails convention for URL mapping.
The browser then retrieves the img like a typical JPG. send_file returns
a byte stream [i.e. no HTTP headers, etc] which is subsequently
rendered..  It all pretty straightforward actually - it's probably worth
reading abt the HTTP 1.1 protocol if you found the previous few lines
This topic is locked and can not be replied to.