草庐IT

request_token

全部标签

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-on-rails - 我得到 "found character that cannot start any token while scanning for the next token"

我已经在我的笔记本电脑上运行RubyonRails大约一个月了,但是当我想在这个实例中运行服务器时(它在几个小时前工作正常)我现在收到这条消息。请问如何让服务器再次运行?C:\Sites\LaunchPage>railssC:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/psych.rb:203:in`parse':():foundcharacterthatcannotstartanytokenwhilescanningforthenexttokenatline17column17(Psych::SyntaxError)fromC:/RailsIns

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

ruby-on-rails - 没有参数的 request.fullpath

request.fullpath给出完整路径加上传递的任何参数,例如/page?param1=value¶m2&value如何只获取没有参数的页面?喜欢/page谢谢。 最佳答案 使用路径代替完整路径。虽然没有记录,request.path对我有用。我通常使用我的插件rails_web_console来处理请求对象。更新:正如turboladen注意到的那样,"[ActionDispatch::Request][2]继承自[Rack::Request‌][3],其中request.path为定义”。path没有记录在那里,但

ruby-on-rails - 如何设置 ActionMailer default_url_options 的 :host dynamically to the request's hostname?

我正在尝试设置:hostforactionmailer默认url选项。我在所有环境文件中设置了以下内容config.action_mailer.default_url_options={:host=>"localhost"}我想通过提供请求主机使其更具动态性。当我尝试通过设置它时config.action_mailer.default_url_options={:host=>request.domain}或config.action_mailer.default_url_options={:host=>request.env["SERVER_NAME"]}它抛出错误...无法识别“请求

ruby - 警告 : Can't verify CSRF token authenticity in case of API development

我现在正在使用RubyonRails开发网络API。当Rails应用程序收到没有任何csrftoken的POST请求时,将出现以下错误消息。因为该应用没有View。WARNING:Can'tverifyCSRFtokenauthenticity所以我的问题是在这种情况下如何安全地逃避csrftoken检查?非常感谢您。 最佳答案 你可以通过添加skip_before_filter:verify_authenticity_token到你的Controller。这样,所有传入Controller的请求都会跳过:verify_authen

ruby-on-rails - Rails 中的 request.remote_ip 和 request.ip 有什么区别?

如题所示,两种方法都可以获取到客户端的ip。我想知道是否有任何差异。谢谢。源码里有"/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action_dispatch/http/request.rb"257L,8741Cdefip@ip||=superend#OriginatingIPaddress,usuallysetbytheRemoteIpmiddleware.defremote_ip@remote_ip||=(@env["action_dispatch.remote_ip"]||ip).to_send但我真

ruby-on-rails - config/environments/development.rb 中 "consider_all_requests_local"的用途?

这个Rails配置设置的目的是什么...config.action_controller.consider_all_requests_local=true在config/environments/development.rb中默认设置为true。谢谢,伊桑 最佳答案 非本地请求会导致用户友好的错误页面。假定来自开发人员的本地请求会看到更有用的错误消息,其中包括行号和回溯。consider_all_requests_local允许您的应用程序显示这些对开发人员友好的消息,即使发出请求的机器是远程的。

ruby-on-rails - Rails 4 真实性 token

当我遇到一些真实性token问题时,我正在开发一个新的Rails4应用程序(在Ruby2.0.0-p0上)。在编写响应json的Controller时(使用respond_to类方法),我得到了create我开始行动ActionController::InvalidAuthenticityToken当我尝试使用curl创建记录时出现异常.我确定我设置了-H"Content-Type:application/json"我用-d""设置数据但仍然没有运气。我尝试使用Rails3.2(在Ruby1.9.3上)编写相同的Controller,但我没有遇到任何真实性token问题。我四处搜索,发