草庐IT

header-files

全部标签

Ruby 需要 'file' 和相对位置

所以我正在编写一些rspec测试,我为自己缺乏对Ruby的理解而感到尴尬。我的文件结构如下所示:GUI_Tests/Tests/test_spec.rbGUI_Tests/windows_gui.rbGUI_Tests/upload_tool.rb当我为test_spec.rb文件运行规范时,我需要像这样包含upload_tool文件:spec-r../upload_tool-fstest_spec.rb然后,upload_tool需要windows_gui.rb,如下所示:require'../windows_gui'我的问题是,为什么我必须相对于test_spec.rb(需要../

ruby - 如何在 Heroku 上托管的 Ruby/Sinatra 应用程序中设置 HTTP header ?

我有一个基于Ruby和Sinatra的工作应用程序部署在Heroku上。我想利用Heroku上可用的HTTP缓存,它使用Varnish。我不确定设置header的最佳方式是什么,以及正确的语法。对最佳方法和语法有什么想法吗?beforedoheaders"Content-Type"=>"text/html;charset=utf8"endget'/'doheaders['Cache-Control']='public,max-age=600'#SOMESTUFFHEREhaml:home,{:layout=>:layout_minfooter}end 最佳答

ruby - 试图构建一个 gem,得到一个 Gem::InvalidSpecificationException: "[...] are not files"

我正在尝试构建一个我编写的名为client_package的自定义gem,但它失败了。我的目录结构是这样的:client_packageGemfileGemfile.lockclient_package.gemspecRakefileReadme.md.gitignore.git...gitfiles...libclient_package.rbclient_packageversion.rbapi.rb...more...我的client_package.gemspec看起来像这样:#encoding:UTF-8requireFile.expand_path('../lib/clie

ruby LoadError : cannot load such file

例如,当我需要一个文件(称为st.rb)时:require'rubygems'require'mongrel'classTestHandler在irb中我得到:>>require'st.rb'LoadError:cannotloadsuchfile--st.rbfrom/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'from(irb):3from/usr/loc

ruby - 从 Ruby HTTP 请求中获取响应 header

我正在使用Net::HTTP通过Ruby发出HTTP请求,但我不知道如何获取所有响应header。我尝试了response.header和response.headers但没有任何效果。 最佳答案 响应对象实际上包含标题。有关详细信息,请参阅“Net::HTTPResponse”。你可以这样做:response['Cache-Control']您还可以在响应对象上调用each_header或each以遍历header。如果您真的想要响应对象之外的header,请调用response.to_hash

ruby-on-rails - 为什么 Ruby "script/generate"返回 "No such file or directory"?

我在使用script/generate时遇到问题。我正在关注treebasednavigation教程,它说使用script/plugininstallgit://github.com/rails/acts_as_tree.git或script/generatenifty_layout。我不断得到:Nosuchfileordirectory--script/plugin我试过这些变体:script/generatenifty_layoutrailsgeneratenifty_layoutrubyscript/generatenifty_layoutrubygeneratenifty_l

ruby - 冒号(:) appears as forward slash (/) when creating file name

我正在使用日期和时间来标记我正在创建的新文件,但是当我查看该文件时,冒号是一个正斜杠。我正在使用10.7+在Mac上开发这是我使用的代码:File.open("#{time.hour}:00,#{time.month}-#{time.day}-#{time.year}","a")do|mFile|mFile.syswrite("#{pKey}-#{tKey}:\n")mFile.syswrite("Itemsclosed:#{itemsClosed}|Totalitems:#{totalItems}|Percentclosed:%#{pClosed}\n")mFile.syswrite

ruby-on-rails - 在 Rails 4 中检测用户代理 - 读取 HTTP header

我刚刚从PHP切换到RubyonRails,想知道是否有一种方法可以检测客户端设备/用户代理(读取HTTPheader),以便根据收到的请求为网站的不同版本提供服务。在PHP中我一直在使用MobileDetect这样做。一般的想法是只提供每个特定版本所需的文件。这就是为什么客户端方法不是那么有效。有没有办法用Ruby2.0.0和Rails4.0.0做类似的事情?也许有gem可以处理这样的情况? 最佳答案 检查request方法,在那里你可以获得ActionDispatch::Request您拥有所有请求参数,包括用户代理。reque

ruby - File.open 带 block vs 不带

我有一个关于Block的问题,这两个代码的意思一样吗?代码1File::open('yozloy.txt','w')do|f|f代码2newFile=File::open('yozloy.txt','w')newFile 最佳答案 不,它们的意思不同。在第一个示例中,文件在处理完block后自动关闭。在第二个示例中,您有责任手动调用newFile.close。 关于ruby-File.open带blockvs不带,我们在StackOverflow上找到一个类似的问题:

ruby - 如何在需要必要的库和/或 header 时安装 ruby​​-debug

我的Rails是3.2.1.4,Ruby是1.9.3p448。我在安装ruby-debug时遇到错误:Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingruby-debug:ERROR:Failedtobuildgemnativeextension./home/hxh/.rvm/rubies/ruby-1.9.3-p448/bin/rubyextconf.rbCan'thandle1.9.xyet***extconf.rbfailed***CouldnotcreateMakefileduetosome