Pull/Display a list of MHTML files in the Public folder and embed them as IFrames in my Rails application views

StackOverflow https://stackoverflow.com/questions/14585948

Question

I have a client that uses SQL Server Reporting Services to generate reports and exports them in MHTML. The Client wants to just push the MHTML in a pre-defined directory structure to my Rails public/reports folder.

Is there any way in Rails to "Take in" the directory structure, create a list of files recursively, generate an unordered list and then create routes dynamically for each MHTML file? I know MHTML files can be embedded with Iframes (although with limited browser support, this is not an issue for me)

The predefined Directory structure is Public/Reports/Dashboard/Exceptions/

Dashboard will contain 1 MHTML file and exceptions (which will be a sort of subnav or child of Dashboard) will contain an undefined amount.

The layout template will be a sort of wrapper.

Anyone who has experience with Rails know the best way of achieving the desired result?

Any help will be sincerely appreciated. I am using Rails 3.0.20 (which doesn't have the Asset pipeline), this will won't be hosted on Heroku (I am aware of no-write permissions)

Was it helpful?

Solution

(Sorry, I'm not super familiar with MHTML files, so I'm going to assume these are just static files that a browser can interpret.)

There is nothing in particular in Rails that provides the behavior that you're referring to. Rails is just a framework to help serve dynamic responses, and the functionality you want is in relation to the filesystem, which Rails mostly abstracts away.

There's a couple options I can think of.

  1. Roll your own

    Ruby has file and directory utilities which you could use to read in the contents of a directory in public and render the kind of response you'd like. I would start here:

    http://www.ruby-doc.org/core-1.9.3/Dir.html

    And play around with ruby's directory globbing to get a file listing.

  2. Use Rack

    Rails is built ontop of Rack, a standard webserver interface that most ruby application server implement now. Rack provides some libraries that make serving static assets like a traditional web server a little easier.

    Here's a couple of resources to check out:

    http://quickleft.com/blog/rack-130-serving-static-files http://edgeguides.rubyonrails.org/rails_on_rack.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top