ruby-on-railsruby-on-rails-4rdocri

How can I browse local project documentation


Is there any Rails way to browse the documentation generated in local doc/ folder with the command rake doc:app?

I know I could configure Apache to serve the files in the doc folder but I would be surprised if Rails didn't provide a way to do that too.


Solution

  • The reason Rails doesn't provide a way to serve it is because it's just static HTML - you can open it in your browser directly (eg. firefox doc/app/index.html), without the need for a server.

    If you wanted, you could add your own Rake task for this in lib/tasks/browserdoc.rake:

    namespace :doc do
        desc "Browse application documentation"
        task :open do
            `firefox doc/app/index.html`
        end
    end
    

    Some systems have browser-agnostic shortcuts you could use instead of hard-coding the browser name; open on Mac OSX will open an HTML file in your current browser, as will sensible-browser on most modern Linux systems.