草庐IT

session_is_registered

全部标签

ruby-on-rails - 为什么我得到 "including Capybara::DSL in the global scope is not recommended!"

每次我运行规范,即使规范通过,例如$rspecspec/integration/view_homepage_spec.rbincludingCapybara::DSLintheglobalscopeisnotrecommended!.Finishedin0.6174seconds1example,0failuresRandomizedwithseed14130$我的Gemfile有:group:test,:developmentdogem'rspec-rails'gem'capybara'end我的spec_helper有:ENV["RAILS_ENV"]||='test'requir

ruby - 如何使用 sinatra session

enable:sessionsget'/foo'dosession['m']='HelloWorld!'redirect'/bar'endget'/bar'dosession['m']#=>'HelloWorld!'end好像不行。 最佳答案 你在用霰弹枪吗?如果是这样,请执行以下操作:configure(:development){set:session_secret,"something"}这在Sinatra1.3中将不再是必需的。 关于ruby-如何使用sinatrasession

ruby - 为什么 'undefined method ` assert_equal' ' is thrown even after requiring ' test/unit'

我打开irb并输入:require'test/unit'但是当我使用assert_equal方法时,出现以下错误:NoMethodError:undefinedmethod'assert_equal'formain:Object。为什么即使在需要“测试/单元”之后也会发生这种情况? 最佳答案 assert_equal是在Test::Unit::TestCase的子类上定义的,因此仅在该类中可用。您可能会成功地使用includeTest::Unit::TestCase将这些方法加载到当前范围。更有可能的是,您最好将测试写在一个短文件中

ruby-on-rails - rake 数据库 :migrate is being aborted due to rake version difference

这个问题在这里已经有了答案:YouhavealreadyactivatedX,butyourGemfilerequiresY(11个答案)关闭8年前。我遇到了错误rakedb:migrate--tracerakeaborted!Youhavealreadyactivatedrake10.1.1,butyourGemfilerequiresrake10.1.0.Usingbundleexecmaysolvethis./Users/iang/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:

ruby - before_session Hook 失败:Pry::CommandError:找不到此方法:加载

在Ruby脚本中加载PryREPL我得到了这个奇怪的错误:before_sessionhookfailed:Pry::CommandError:Cannotlocatethismethod:load.~/.rvm/gems/ruby-2.0.0-p195/gems/pry-0.9.12.2/lib/pry/method.rb:498:in`pry_doc_info'(see_pry_.hooks.errorstodebug)知道问题出在哪里吗?注意事项:1.除了那个神秘的消息之外,代码似乎执行得很好,并且2.我找不到“_pry_.hooks.errors”文件

ruby-on-rails - rails 引擎 : rake routes show its routes but on rspec execution "No route matches" is thrown

我正在尝试测试我的应用程序正在使用的引擎内部的Controller。规范不在引擎中,而是在应用程序本身中(我试图在引擎中进行测试,但也遇到了问题)。我的引擎有以下routes.rb:Revision::Engine.routes.drawdoresources:steps,only:[]docollection{get:first}endend引擎正常挂载在应用routes.rb上:mountRevision::Engine=>"revision"当我运行rakeroutes时,在最后一行我得到:RoutesforRevision::Engine:first_stepsGET/step

ruby-on-rails - Ruby BigDecimal 圆 : Is this an error?

在用一个表示为BigDecimal的值编写测试时,我遇到了一些奇怪的事情并决定深入研究它。简而言之,四舍五入到小数点后两位的“0.00009”返回为0.01而不是0.00。真的。这是我的脚本/控制台捕获:>>bp=BigDecimal('0.09')=>#>>bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f=>0.09>>bp=BigDecimal('0.009')=>#>>bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f=>0.01>>bp=BigDecimal('0.0009')=>#>>bp.roun

ruby-on-rails - 使用 ruby​​ mechanize 在浏览器中存储登录 session cookie

我正在尝试登录网站并通过Rails操作重定向到安全页面。我的代码看起来像这样。defredirect_to_externalagent=Mechanize.newpage=agent.get('http://example.com/home.asp')login_form=page.form_with(:name=>"loginForm")login_form.login='username'login_form.password='password'agent.submit(login_form)#cookies=agent.cookie_jar.store.map{|i|i}#ne

ruby - Rack::Session::Pool 与 Sinatra

我有一个使用enable:sessions构建的Sinatrawebapp,我使用session[:mything]访问我的session数据。我现在想在服务器端存储数据(即使用基于数据库的session),但我不知道如何使用Rack::Session::Pool,这似乎是我需要使用的东西。我如何着手转换我的网络应用程序以与Pool一起使用?我知道我需要添加行useRack::Session::Pool接下来会发生什么?—提前致谢!编辑:这是一个使用基于cookie的session的示例:require'rubygems'require'sinatra'enable:sessionsg

ruby - "Assignment Branch Condition size for index is too high"是如何工作的?

Rubocop总是报告错误:app/controllers/account_controller.rb:5:3:C:AssignmentBranchConditionsizeforindexistoohigh.[30.95/24]ifparams[:role]@users=@search.result.where(:role=>params[:role])elsifparams[:q]&¶ms[:q][:s].include?('count')@users=@search.result.order(params[:q][:s])else@users=@search.result