美文网首页sinatra学习
Sinatra学习 day 5

Sinatra学习 day 5

作者: 长物记 | 来源:发表于2015-05-31 20:44 被阅读114次

    RESTful URLs

    直接参考rails routing

    Sinatra直接提供了这些http verb

    get '/path' do
        code here
    end
    
    get '/path/new' do
        code here
    end
    
    get '/path/:id' do
        code here
    end
    
    post '/path' do
        code here
    end
    
    put '/path/:id' do
        code here
    end
    
    delete '/path/:id' do
        code here
    end
    

    Configuration

    Sinatra提供了一个configure函数,任何配置信息都在放在这个代码块下

    configure do
        code here
    end
    

    3个开发环境

    如果在生产环境运行sinatra,直接

    ruby main.rb -e production
    

    sinatra也提供了环境函数

    development?
    test?
    production?
    
    configure :test do
        code here
    end
    

    自定义

    sinatra提供了settings对象,可以获取它的setting值

    setttings.port
    

    你也可以自己设置setting值

    set :name,'sinatra web'
    

    还有一些built-in的settings可以定义

    set :views,'/views'
    

    更多参考configuration
    当设置值为boolen,可以使用简单的函数

    set :logging,true
    

    可以改为

    enable :logging
    

    关闭

    disable :logging
    

    相关文章

      网友评论

        本文标题:Sinatra学习 day 5

        本文链接:https://www.haomeiwen.com/subject/ngfdqttx.html