草庐IT

ajax-request

全部标签

ruby-on-rails - 助手设计 : could not find the `Warden::Proxy` instance on request environment

我尝试将Devise用于我的Rails应用程序。我可以注册并登录,但是当我转到其他页面“构建”时,出现以下错误:Devise::MissingWardeninHome#showDevisecouldnotfindtheWarden::Proxyinstanceonyourrequestenvironment.MakesurethatyourapplicationisloadingDeviseandWardenasexpectedandthattheWarden::Managermiddlewareispresentinyourmiddlewarestack.Ifyouareseeing

ruby-on-rails - rails : switch connection on each request but keep a connection pool

在我们的Rails应用程序中,我们需要根据请求的子域使用不同的数据库(每个国家/地区使用不同的数据库)。现在我们正在做类似于thisquestion中推荐的事情.也就是说,在每个请求上调用ActiveRecord::Base.establish_connection。但是itseemsActiveRecord::Base.establish_connection删除当前连接池并在每次调用时建立一个新连接。我做了这个快速基准测试,看看每次调用establish_connection和已经建立连接之间是否有任何显着差异:require'benchmark/ips'$config=Rails

ruby - 加载网页时 : "undefined method ` request_uri' for #"

我正在尝试使用Ruby通过HTTP加载网页并检查其状态代码是什么。我的代码如下所示:require"net/http"@r=Net::HTTP.get_response(URI.parse(myURL))return@r.code但是,对于某些URL(主要是指向奇怪的东西,例如不会给出正确响应的Web计数器),我得到了一个undefinedmethodrequest_urifor#异常。我已经将它追溯到http.rb的第380行(我正在运行Ruby1.8),它说:defHTTP.get_response(uri_or_host,path=nil,port=nil,&block)ifpa

ruby-on-rails - rails 4 : How to upload files with AJAX

我想使用AJAX上传文件。在过去,我通过使用神奇的jQueryformplugin来实现这一点。效果很好。目前我正在构建一个Rails应用程序并尝试以“Rails方式”做事,所以我正在使用FormHelper和回形针gem来添加文件附件。railsdocs警告FormHelper不适用于AJAX文件上传:Unlikeotherformsmakinganasynchronousfileuploadformisnotassimpleasprovidingform_forwithremote:true.WithanAjaxformtheserializationisdonebyJavaScr

ruby-on-rails - 我如何在 Rails 的模型中获取 request.uri?

$request=request当我在Controller中编写它时,它会起作用。但是,如果我在模型或应用程序Controller中需要这个变量,我该怎么办? 最佳答案 模型存在于网络请求的上下文之外。您可以在irb中实例化它们,您可以在延迟作业或脚本中实例化它们,等等。如果模型依赖于请求对象,那么这些事情都不可能发生。正如tsdbrown所说,您必须以某种方式从使用模型的上下文中传递该信息。 关于ruby-on-rails-我如何在Rails的模型中获取request.uri?,我们在

ruby-on-rails - rails : Plus sign in GET-Request replaced by space

在Rails3(Ruby1.9.2)中我发送一个请求StartedGET"/controller/action?path=/41_+"但是参数列表是这样的:{"path"=>"/41_","controller"=>"controller","action"=>"action"}这里出了什么问题?-、*或.符号工作正常,只是+将被空格替换。 最佳答案 这是正常的URL编码,theplussignisashorthandforaspace:Withinthequerystring,theplussignisreservedasshor

ruby-on-rails - 在 Rails 4 中接收 POST 数据并读取 request.body

我想向Rails应用程序发送POST请求,并让它在数据库中保存和解析请求主体...我在接收端的路线目前设置为:post'/request'=>'controller#receives_data'当我将数据发布到我使用的这个Controller时:defpost_itconnection.post(uri.path,"thisisdata",header_with_authkey)end我接收帖子的Controller方法设置为:defreceives_datalog(request.body.read)end但是我得到了一个422错误,无法处理的实体,并且日志文件总是空的...是否需要

ruby-on-rails - 我如何在我的 RSpec 中设置 request.referrer?

我试图避免使用我的session[:referred_by],而想使用request.referrer。但是,我的RSpec测试失败了,因为TestRequest没有存储request.referrer因此,为了使Rspec测试正常工作,我必须执行以下操作。有没有办法让它变得更好:referrer=request.referrer?request.referrer:'/'redirect_toreferrer,:alert=>error_message 最佳答案 ActionDispatch::TestRequest扩展了Actio

ruby - 如何在 OpenURI 中指定 "http request header"

我正在尝试使用Ruby的OpenURIgem调用URL,但是它需要我在其HTTP请求header中传递某些值。知道怎么做吗? 最佳答案 根据thedocumentation,您可以将httpheader的哈希值作为第二个参数传递给open:open("http://www.ruby-lang.org/en/","User-Agent"=>"Ruby/#{RUBY_VERSION}","From"=>"foo@bar.invalid","Referer"=>"http://www.ruby-lang.org/"){|f|#...}

ruby - Rack::Request - 如何获取所有 header ?

标题是不言自明的。有什么方法可以获取header(Rack::Request.env[]除外)? 最佳答案 HTTPheader在Rackenvironment中可用。传递给您的应用:HTTP_Variables:Variablescorrespondingtotheclient-suppliedHTTPrequestheaders(i.e.,variableswhosenamesbeginwithHTTP_).Thepresenceorabsenceofthesevariablesshouldcorrespondwiththepr