草庐IT

cookie-config

全部标签

ruby-on-rails - 可以将哈希存储在 cookie 中吗?

有人知道我是否可以在cookie中放入哈希值吗?像这样:cookies[:test]={:top=>5,:middle=>3,:bottom=>1}谢谢 最佳答案 我会考虑序列化散列来存储它。然后反序列化它以检索它。当您序列化哈希时,结果将是一个编码字符串。可以对该字符串进行解码以取回原始对象。您可以为此使用YAML或JSON。两者都在Ruby中得到很好的支持。一个YAML示例require"yaml"cookies[:test]=YAML::dump{a:1,b:"2",hello:"world"}#=>"---\n:a:1\n:

ruby - capybara 与 cucumber |获取 cookie

我试图在Cucumber步骤中获取cookie值:步骤定义When/^Ilogin$/do#codetologinendThen/^cookiesshouldbeset$/docookies[:author].should_notbe_nilendControllerclassSessionsController但它不起作用:结果expected:notnilgot:nil在RSpec示例中,一切正常:Controller规范require'spec_helper'describeSessionsControllerdodescribe'create'doit'setscookies'

ruby-on-rails -/config/initializers/secret_token.rb 未生成。为什么不?

目前正在阅读Rails教程,我需要对/config/initializers/secret_token.rb进行一些修改,但是,我无法在initializers目录。我正在运行最新版本的Rails。这是我在终端中用来创建rails项目的行:railsnewsample_app有人知道为什么它没有出现吗? 最佳答案 感谢您指出这一点。问题可能是由于使用Rails4.1而不是Rails教程中指定的Rails4.0。就是因为这样的问题Section1.2.2州(原文为粗体)Unlessotherwisenoted,youshoulduse

ruby - 如何使用( ruby ) Rack 中间件组件设置 cookie?

我正在为需要有条件地设置cookie的Rails应用编写Rack中间件组件。我目前正在尝试设置cookie。通过谷歌搜索,这似乎应该可行:classRackAppdefinitialize(app)@app=appenddefcall(env)@status,@headers,@response=@app.call(env)@response.set_cookie("foo",{:value=>"bar",:path=>"/",:expires=>Time.now+24*60*60})[@status,@headers,@response]endend它不会给出错误,但也不会设置coo

ruby-on-rails - Ruby on Rails config.secret_token 错误

我刚开始学习RubyonRails。我遵循了很多安装示例,但是当我运行示例时出现此错误为cookiesession数据生成完整性散列需要一个secret。在config/initializers/secret_token.rb中使用config.secret_token="somesecretphraseofatleast30characters"我搜索它,但没有看到太多帮助。请帮忙。平台:MacOSX。 最佳答案 生成新secrettoken的最简单方法是运行rakesecret在命令行。

ruby-on-rails - 为什么 Rails 生成运行类而不是对象的 config.ru?

RackspecifiesARackapplicationisaRubyobject(notaclass)thatrespondstocall.因此,一个简单的config.ru看起来像这样:classMyAppdefcall(env)[200,{"Content-Type"=>"text/plain"},["HellofromRack!\n"]]endendrunMyApp.new当Rails生成这个时:#ThisfileisusedbyRack-basedserverstostarttheapplication.require::File.expand_path('../confi

ruby-on-rails - Rspec.config 之前(:each) except for specific :types

我正在尝试获取一个before(:each)block以针对所有规范excepttype::feature运行。我让它工作的唯一方法是剪切和粘贴,并为每种类型设置单独的配置block。(:type=>:model,:type=>:service等)spec/rails_helper.rb#Tospeeduptests,stuballPaperclipsavingandreadingto/fromS3config.before(:each,:type=>:model)doallow_any_instance_of(Paperclip::Attachment).toreceive(:sav

ruby-on-rails - 如何防止 Rails Controller 生成器修改 config/routes.rb

有时我会运行类似railsgcontrollerfooindex的命令来生成Controller和模板的骨架。因为我不希望每个Controller都有助手和Assets,所以我将以下代码放入config/application.rb:config.generatorsdo|g|g.helperfalseg.assetsfalseend还有一件事我不想发生。生成器将一行get"foo/index"添加到我的config/routes.rb。我该如何预防? 最佳答案 从Rails4.2开始,可以在application.rb中使用以下代

ruby-on-rails - 如何从 ApplicationController (Rails) 访问 cookie

我想访问cookie,然后执行相同的操作,而不管操作或Controller如何。我不想编写一个从我的无数操作方法中的每一个调用的方法,因为除了痛苦之外,它不会产生非常敏捷的代码。我宁愿从application_controller.rb中的ApplicationController类(所有Controller类的父类(superclass))调用我的cookie处理方法。但是,在ApplicationController类的主体中调用cookies()会引发“未定义方法”错误。(我想cookies直到后来才被定义。)我能做什么?我是否应该覆盖ApplicationController的

ruby - Sinatra/1.4.3 使用 Rack::Session::Cookie 警告

我的配置代码require'sinatra'#set:environment,:productionenable:sessionsenable:loggingsetrun:truecasewhenproduction?setport:8081whendevelopment?require'sinatra/reloader'require'better_errors'useBetterErrors::MiddlewareBetterErrors.application_root=__dir__enduseRack::Session::Cookie,key:'N&wedhSDF',doma