草庐IT

current_file

全部标签

ruby - 使用 WWW :Mechanize to download a file to disk without loading it all in memory first

我正在使用Mechanize来简化某些文件的下载。目前我的脚本使用以下行来实际下载文件...agent.get('http://example.com/foo').save_as'a_file_name'然而,这会将完整的文件下载到内存中,然后再将其转储到磁盘。你如何绕过这种行为,直接下载到磁盘?如果我需要使用WWW:Mechanize以外的东西,那么我将如何使用WWW:Mechanize的cookies呢? 最佳答案 您真正想要的是Mechanize::Downloadhttp://mechanize.rubyforge.org/

ruby-on-rails - ruby rails : How do you check if a file is an image?

如何检查文件是否为图像?我想你可以使用这样的方法:defimage?(file)file.to_s.include?(".gif")orfile.to_s.include?(".png")orfile.to_s.include?(".jpg")end但这可能有点低效而且不正确。有什么想法吗?(我正在使用回形针插件,顺便说一句,但我没有看到任何方法来确定文件是否是回形针中的图像) 最佳答案 请检查一次MIME::Types.type_for('tmp/img1.jpg').first.try(:media_type)=>"image"

ruby-on-rails - Rails + Twitter Bootstrap : File to import not found or unreadable: twitter/bootstrap

我正在尝试使用TwitterBootstrap(gemtwitter-bootstrap-rails)设置Rails应用程序,但我仍然无法克服错误Filetoimportnotfoundorunreadable:twitter/bootstrap.我在gem的官方Github上发现了这个问题,但是那里的解决方案都对我不起作用。这是我的设置:gem文件gem"twitter-bootstrap-rails"gem'font-awesome-rails'gem'sass-rails','~>3.2.3'group:assetsdo#gem'sass-rails','~>3.2.3'gem'

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 3.1 : Trouble on displaying images in mailer view files

我正在使用RubyonRails3.1,我想将我的网站Logo(即通过新Assets管道处理的图像)添加到电子邮件中。如果在我的邮件View文件中声明如下:它在production模式下不起作用(也就是说,我无法显示Logo图像),因为我认为Assets管道使用指纹识别技术并且在收到的电子邮件中它没有.检查电子邮件中的HTMLLogo元素,我得到如下信息:#withoutFingerprinting我该如何解决这个问题?在我的production.rb文件中,我有以下注释掉的代码:#Enableservingofimages,stylesheets,andjavascriptsfrom

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-on-rails - 如何在 rspec 功能测试中访问(设计)current_user?

在设计文档中,他们提供了有关在测试Controller时如何访问current_user的提示:https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29但是,在进行功能测试时呢?我正在尝试测试我的一个Controller的创建方法,并且在该Controller中使用了current_user变量。问题是devise中建议的宏使用了@request变量,并且对于功能规范来说它是nil。什么是解决方法?编辑:这是我目前的规范:feature

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-on-rails - Rails : how to get the current host, 或用它构建 URL?

这个问题在这里已经有了答案:GettingtheHostnameorIPinRubyonRails(12个答案)关闭8年前。我需要使用主机构建具有不同端口的URL。例如,如果主机是example.com,我需要生成类似http://example.com:8080/的URL我需要它是便携的,所以当我在本地环境中时,它会显示http://localhost:8080/相反。有什么想法吗?