Static page routing in Sinatra (Ruby)

前端 未结 6 839
醉酒成梦
醉酒成梦 2021-02-13 13:39

You can serve static files with Sinatra by placing them in public/ (by default) -- I have an index.html in there at the moment, but how can I make the

6条回答
  •  梦谈多话
    2021-02-13 14:11

    Just set enable :static inside of your app class. Like so:

    class App < Sinatra::Base
      # Set the app root; this is where the 'public' and 'views'
      # directories are found (by default).
      set :root, File.expand_path("#{File.dirname(__FILE__)}/../app")
    
      # Allow the app to serve static files from the 'public' directory in :root
      enable :static
    end
    

提交回复
热议问题