English 中文(简体)
Sinatra的厨师在某些路线上消失?
原标题:Sinatra cookies vanish on certain routes?

我很简单的Sinatra说,我正在玩弄,而且出于某种原因,厨师似乎不为某些路线工作,我认为这些路线是很荒谬的。

require "sinatra"

set(:authenticate) do |*vars|
    condition do
        unless request.cookies.has_key?("TestCookie")
            redirect to("/login"), 303 
        end
    end
end

get "/login" do
    return "No valid cookie"
end

get "/secret", :authenticate => [:auth_cookie] do
    cookie = request.cookies["TestCookie"]
    return "Secrets ahoy - #{cookie}"
end

get  /cookie/set  do
    response.set_cookie("TestCookie", {
        :expires => Time.now + 2400,
        :value => "TestValue"
    })
    return "Cookie is set"
end

get  /cookie/get  do
    cookie = request.cookies["TestCookie"]
    return "Cookie with value #{cookie}"
end

如果我去做厨师/get,那么,如果我去做饭,我就获得正确的厨师产出。 然而,如果我去/听说,总是向 转头。 由于我对Ruby syntax仍然很新,我认为,在真实的延期中,我的状况可能是一个问题,因此,我已尝试取消这一条件,只是像另一个人那样 out。 不管怎么说,因此,我对 co在哪里感到损失,我可以把它看在浏览器中......和/ook/植被工程中,但......

我在这里找不到什么东西?

最佳回答

问题是, co与条码(<>/cookie)一致。 当你确定一个厨师时,你可以指明一条道路,实际上,这条道路是你希望该厨师申请的网站的一个小部分。 I guess Sinatra/Rack在/cookie/set上的缺席情况下使用目前请求的道路。 页: 1

你们可以通过明确指明以下道路来做到这一点:

  response.set_cookie("TestCookie", {
    :expires => Time.now + 2400,
    :value => "TestValue",
    :path =>  / 
  })

或者,你可以在一个叫做/cookie-set的线路上安装 co。 而不是<代码>/cookie/set

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签