Search code examples
ruby-on-railsrubyherokuwebrick

In RoR how can I set the default file DirectoryIndex?


In Apache I can use DirectoryIndex to specify different files or extensions to be the default served--how do I accomplish this with RoR? In the public directories I have a few folders that need to serve JS files as the index.

With Apache, I'd do:

DirectoryIndex index.js

I'm using WEBrick locally and Heroku for production.


Solution

  • I ended up creating a controller that loaded in the JS, like

    def show
      output = File.read("public/js/stats/index.js")
      render :text => output
    end
    

    Then I created a route

    match 'stats/index' => 'stats#show'
    

    May not be the most elegant, but I think it was easier than managing dependencies between local and production environments