jjzjj

invalid_request

全部标签

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 `split' : invalid byte sequence in UTF-8 (ArgumentError)

我正在尝试填充电影对象,但在解析u.item文件时出现此错误:`split':invalidbytesequenceinUTF-8(ArgumentError)File.open("Data/u.item","r")do|infile|whileline=infile.getsline=line.split("|")endend仅当尝试使用花哨的国际标点符号拆分行时才会发生错误。这是一个例子543|Misérables,Les(1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Mis%E9rables%2C%20Les%20%281

ruby-on-rails - Rails 4 + Devise : Invalid route name, 已在使用中

我正在按照此操作方法在成功注册后修改确认页面。https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)我按照它所说的做了所有事情,但我得到了这个错误:in`add_route':Invalidroutename,alreadyinuse:'new_user_session'(ArgumentError)Youmayhavedefinedtworouteswiththesamenameusingthe`:as`o

ruby-on-rails - Ruby 2.0.0 字符串#Match ArgumentError : invalid byte sequence in UTF-8

我经常看到这种情况,但还没有想出一个优雅的解决方案。如果用户输入包含无效的字节序列,我需要能够让它不引发异常。例如:#@raw_responsecomesfromuserandcontainsinvalidUTF-8#forexample:@raw_response="\xBF"regex.match(@raw_response)ArgumentError:invalidbytesequenceinUTF-8已经问了很多类似的问题,结果似乎是对字符串进行编码或强制编码。然而,这些都不适合我:regex.match(@raw_response.force_encoding("UTF-8"

ruby-on-rails - Rails 3 安装错误 : "invalid value for @cert_chain"

我正在尝试在一台新的OSXSnowLeopard机器(安装了开发工具)上安装Rails3,当我sudogeminstallrails时,我收到以下错误:ERROR:Whileexecutinggem...(Gem::FormatException)builder-2.1.2hasaninvalidvaluefor@cert_chain更新失败。有没有人见过这个?我grep为“cert_chain”编辑了builder-2.1.2目录,但找不到任何线索。Ruby版本是1.8.7OSX10.6.6谢谢! 最佳答案 这是Rubygems1

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