How to render a plain HTML file with Sinatra?

前端 未结 3 1250
你的背包
你的背包 2020-12-29 04:06

I have a simple sinatra application. All I want to do is use it as a wrapper to serve a static HTML file at a specific route. My directory structure looks like this:

相关标签:
3条回答
  • 2020-12-29 04:32

    You can do it like this:

    get '/myspecialroute' do
      redirect '/myspecialroute.html'
    end
    
    0 讨论(0)
  • 2020-12-29 04:37

    This is work for me:

    require 'rubygems'
    require 'sinatra'
    
    get '/index.html' do
        @page_title = 'Home'
        @page_id = 'index.html'
        erb :'index.html', { :layout => :'layout.html' }
    end
    
    0 讨论(0)
  • 2020-12-29 04:42

    Does send_file do what you want?

    e.g.

      get '/myspecialroute' do
         send_file 'special.html'
      end
    
    0 讨论(0)
提交回复
热议问题