草庐IT

file_full_path

全部标签

ruby - 导轨 : how to get a file extension/postfix based on the mime type

我的问题是,RubyonRails是否具有类似于以下的功能:file_content_type=MIME::Types.type_for(file).first.content_type这将返回特定mime类型的文件扩展名或后缀?所以如果我传入'image/jpeg'函数将返回'jpg'寻找一种比编写完成相同工作的case语句更简洁的编码方式。 最佳答案 Rack::Mime具有这种能力(Rack是Rails的依赖):require'rack/mime'Rack::Mime::MIME_TYPES.invert['image/jpe

RubyGems + Cygwin : POSIX path not found by ruby. exe

我是Windows上的Ruby程序员,试图从Wincmd切换到Cygwin,但无法执行Rubygems的批处理文件。我已经将任何bin目录填充到WindowsPATH环境中。变量,包括存储可执行文件的Rubybin。然而,gems是由ruby​​.exe本身调用的,这会导致以下POSIX路径问题:duddle@duddledan/cygdrive/c/Ruby/ruby-186-398/bin$gem-vC:\Ruby\ruby-186-398\bin\ruby.exe:Nosuchfileordirectory--/cygdrive/c/Ruby/ruby-186-398/bin/g

ruby - 加载错误 : cannot load such file -- rspec/core/rake_task

当我rake的时候,我得到了这个错误。AllenLins-MacBook-Pro:geoblacklightallenlin$rake-tResolvingdependencies...Youmust`geminstallbundler`and`bundleinstall`torunraketasksrakeaborted!LoadError:cannotloadsuchfile--rspec/core/rake_task/Users/allenlin/Documents/USpatial/geoblacklight/Rakefile:12:in`require'/Users/alle

ruby - "file.sync = true"是做什么的?

我查看了文档,但似乎找不到相关部分。谁能告诉我以下代码中调用sync的目的是什么?fh=Tempfile.new('tmp')fh.sync=true 最佳答案 它设置文件的同步模式。这会影响future的操作并导致在没有block缓冲的情况下写入输出。如果f.tty?为真,也就是说,如果文件连接到类似控制台的设备,则输出不是block缓冲的。但是,当输出到管道或文件时,f.tty?将为false,I/O库将切换到block缓冲,也就是说,将输出累积到一个缓冲区并仅在文件关闭、程序退出或缓冲区已满时写入它。这样速度更快,最终结果相同

ruby - Rails current_path helper ?

我正在开发具有以下路由条件的Rails3.2应用程序:scope"(:locale)",locale:/de|en/doresources:categories,only:[:index,:show]get"newest/index",as::newestend我有一个包含以下内容的Controller:classLocaleController我在模板中将它与类似的东西一起使用:=link_toset_locale_path(locale::de,return_to:current_path(locale::de))do=image_tag'de.png',style:'vertic

ruby - OS X 10.5 下 Ruby 的常规 GEM PATHS 是什么?

我的ruby​​在我的机器上有一个性能问题,我认为我已经隔离到加载库(当调用#require时),所以我试图弄清楚ruby​​是否正在为库搜索太多文件夹。当我运行时$gemenvironmentRubyGemsEnvironment:-RUBYGEMSVERSION:1.3.0-RUBYVERSION:1.8.6(2008-03-03patchlevel114)[universal-darwin9.0]-INSTALLATIONDIRECTORY:/Library/Ruby/Gems/1.8-RUBYEXECUTABLE:/System/Library/Frameworks/Ruby.

ruby - Vagrant File Chef 属性

我正在尝试将我的Vagrant文件配置为具有一些Chef属性,但我一定是做错了什么,因为ChefRecipe使用的是默认值而不是我试图设置的属性。这是我的vagrant文件的配置部分:config.vm.provision:chef_solodo|chef|chef.json={:mysql=>{:server_root_password=>'password'},:nodejs=>{:version=>'0.6.14',:dir=>'/usr/local',:npm=>'1.1.13'}}chef.cookbooks_path="config/env/cookbooks"chef.a

ruby-on-rails - ruby 错误 : cannot load such file -- rest-client

我正在使用RubyonRails4。我正在努力require'rest-client'在我的Controller中,以便我可以解析从表单中获取的登录信息并将其发送到API。我可以验证gem是否已安装并且也在我的应用程序根目录下的Gemfile中。但是,当我尝试在我的Controller中请求该文件时,它仍然抛出“无法加载此类文件--rest-client”。我用谷歌搜索了这个错误,我看到的大部分答案要么是gem没有安装,要么不在Gemfile中,要么是两者兼而有之。这里的情况也不是。我的Controller是否由于某种原因无法访问rest-clientgem?我必须使用rest-cli

ruby-on-rails - 在 `require' : no such file to load -- iconv (LoadError)

➜expertizagit:(master)✗ruby-vruby1.8.7(2011-06-30patchlevel352)[i686-darwin11.1.0]➜expertizagit:(master)✗rails-vRails2.3.14➜expertizagit:(master)✗script/server/Users/HPV/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-2.3.14/lib/active_support/inflector.rb:3:in`require':nosuchfiletoload--iconv(Load

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/