Forum: Ruby on Rails viewing text docs

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.
A63871da93ed2dace4f9e2d1bdb62ff3?d=identicon&s=25 Jason Gagne (jg33)
on 2007-02-27 18:12
I'm building an app that lets users post documents that other users can
view. The format to the type of document doesn't hold up with a cut and
paste so they have to upload. My question is how to display the content
of a document uploaded to the site without the user having to download
the file. Any help would be great.

Thanks

J
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-27 18:27
(Received via mailing list)
it's going to depend on the type of document.
2017657725dd1bce83dc8a1e2e991d04?d=identicon&s=25 Luke Ivers (Guest)
on 2007-02-27 18:37
(Received via mailing list)
I agree with Chris... it can vary very widely depending on the type of
document... basically, what you need is a way to parse the document on
the
server and display it in the page as HTML... HTML being one of the very
few
things you can push across the internet and expect someone to receive...
there are converters for a lot of different document types, you could
possibly conceivably generate an image of the document somehow, etc...
but
it will all hinge on what kind of document it is.
755d28f5c7e6b1af2fbe349b179fe220?d=identicon&s=25 Chet (Guest)
on 2007-02-27 19:21
To add to Luke and Chris -

Also be aware that it will be your hosting server doing the reading
before any document is served. e.g. If you upload a powerpoint file from
a windows machine, the server would need converters/readers to read that
file type.

Might be easy for a text document. If you are storing the file on the
server, you could simple use

    # Return the contents of a file as a string
    def file_to_str(filename)
       rv = ""

       if File.exist?(filename) == false
          rv =  nil
        else
          File.open(filename, "rb") do |infile|
             rv = infile.read
          end
      end
      rv
    end

to retrieve the file contents as string and serve it any way you want.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-27 19:32
(Received via mailing list)
my experience with handling document assets on the web, be they word
docs, pdfs, spreadsheets, whatever, is that you should rely on the
browser and OS to handle the display.  No matter how you look at it,
the file data has to be 'downloaded', whether it's displayed in the
page as html or via a plugin or opened in Word.  all you should worry
about is setting the correct headers then sending the data.

ex: i click a link to a Word document, Open Office opens to display
the document.  I click on a pdf document and the Acrobat plugin
displays the document within the browser.

Chris
A63871da93ed2dace4f9e2d1bdb62ff3?d=identicon&s=25 Jason Gagne (jg33)
on 2007-02-27 19:46
The docs will be limited to pdf files. So, if the OS handles the
display, the view should just link_to what, the file itself or is there
a method that needs to be called on it to tell the os have the Acrobat
plugin display it? Sorry for the rookie questions but, I'm a rookie.

Thanks for all the help

J
Chris Hall wrote:
> my experience with handling document assets on the web, be they word
> docs, pdfs, spreadsheets, whatever, is that you should rely on the
> browser and OS to handle the display.  No matter how you look at it,
> the file data has to be 'downloaded', whether it's displayed in the
> page as html or via a plugin or opened in Word.  all you should worry
> about is setting the correct headers then sending the data.
>
> ex: i click a link to a Word document, Open Office opens to display
> the document.  I click on a pdf document and the Acrobat plugin
> displays the document within the browser.
>
> Chris
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-02-27 20:46
(Received via mailing list)
Your browser should handle a link to a pdf if you have the plugin or
reader installed.  Worse case is your browser will open a dialog and
ask if you want to save or open with whatever your default viewer is
set to.

I believe that with the Acrobat plugin, it will open the document
directly in the browser.

one thing i've done in the past is have an iframe setup for displaying
documents using the acrobat plugin.   you can then target that iframe
from the link and the acrobat plugin should open within the targeted
iframe and display your document.

Chris
This topic is locked and can not be replied to.