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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-04-13 05:42
(Received via mailing list)
Hi,
Thanks a lot for the response. If you can post a working example, that
would be great.
Really appreciate it.
Thanks
Silvy Mathews
John B. (Guest)
on 2006-04-14 02:24
(Received via mailing list)
Here's a [very] rough, but working example for a PDF..

Controller:

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

View:

<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..

brez
Silvy (Guest)
on 2006-04-14 03:04
(Received via mailing list)
Hi John,
That really worked. I did not knew that we could specify a controller
name
and the method name inside the view. Thanks a lot. Really appreciate
that.

Thanks
Silvy
Brez! !. (Guest)
on 2006-04-14 10: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
compelling..
This topic is locked and can not be replied to.