草庐IT

commonjs-why-and-how

全部标签

ruby-on-rails - ruby rails : Unit Testing non activerecord models and still load fixtures

我可能遗漏了一些东西,但我陷入了这种情况:我有一个非activerecord模型,我想对其进行测试。我从Test::Unit::TestCase派生了它的测试用例类。但是,模型的测试用例类在其自身内部使用了其他activerecord模型类,我想为它们加载固定装置。我的问题是fixtures类方法仅在我从ActiveSupport::TestCase继承测试用例类时才可用(它在ActiveRecord::TestFixtures包含在ActiveSupport::TestCase中)。任何帮助,因为运行测试都会给我错误:未定义的方法“fixtures”(这是可以理解的),如果我从Act

ruby - 在我的 ramaze 应用程序上显示 £ 符号时,我收到 "incompatible character encodings: CP850 and UTF-8"

在我的ramaze应用程序上显示£符号时,我收到“不兼容的字符编码:CP850和UTF-8”。我怎样才能摆脱这个错误?我的head标签中有UTF-8元标签。当我用键盘输入£符号时会发生这种情况。看。我已将以下代码放入我的ruby​​文件中,但没有解决问题。#encoding:UTF-8Encoding.default_external='utf-8'Encoding.default_internal=Encoding::UTF_8 最佳答案 尝试强制编码以查看是否可以解决问题:your_string.force_encoding(:

ruby-on-rails - rails : How to to download a file from a http and save it into database

我想创建一个RailsController,从网上下载一系列jpg文件,并直接将它们作为二进制文件写入数据库(我不是要上传表格)关于如何做到这一点的任何线索?谢谢编辑:这是我已经使用attachment-fugem编写的一些代码:http=Net::HTTP.new('awebsite',443)http.use_ssl=truehttp.verify_mode=OpenSSL::SSL::VERIFY_NONEhttp.start(){|http|req=Net::HTTP::Get.new("image.jpg")req.basic_authlogin,passwordrespon

ruby - 如何在 rails_admin 的编辑表单中隐藏 "Save and Add Another"按钮?

我在我的Rails应用程序中应用了rails_admingem。我想删除特定模型编辑表单中一些不必要的按钮,并添加我自己的自定义按钮。请查看屏幕截图,了解我要删除的内容。 最佳答案 @montells复制https://github.com/sferik/rails_admin/blob/master/app/views/rails_admin/main/_submit_buttons.html.haml这个页面在你的repo中,位于“views/rails_admin/main/_submit_buttons.html.haml”

ruby - 要去除\r and\n 或\r\n 的正则表达式

我使用以下正则表达式制作换行符标签:str.gsub("\r\n",'')这在桌面上运行良好。在iphone上文本只有\n,没有\r。我怎样才能使正则表达式支持?\r\n还是只是\n?谢谢 最佳答案 我觉得str.gsub(/\r?\n/,'')应该做的工作 关于ruby-要去除\rand\n或\r\n的正则表达式,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/9107658/

ruby-on-rails - ruby rails : How do you list the partial paths that are rendered for a page?

我希望列出为我的应用程序中的每个页面呈现的部分内容。例如,当显示app/tasks/index.html.erb页面时,我想向用户显示如下内容:Partialsrenderedforthispage:tasks/_list.html.erbtasks/_button.html.erbtasks/_navigation.html.erb在RubyonRails中有什么方法可以做到这一点吗? 最佳答案 是的,在Rails中完全可以做到这一点!正如bdares在他的评论中指出的那样,用于模板渲染的行出现在日志中。但他们最初是如何到达那里的

ruby-on-rails - rails/Prawn : how do I use rails helpers inside a Prawn class?

我正在尝试在prawn类中使用rails3.2助手,但rails抛出:undefinedmethod`number_with_precision'for#Prawn类classQuotePdfControllerdefshow@quote=current_user.company.quotes.where(:id=>params[:id]).firsthead:unauthorizedandreturnunless@quoterespond_with@quote,:layout=>!params[:_pjax]do|format|format.pdfdosend_dataQuotePd

ruby-on-rails - RubyOnRails : How do I use helper methods in Rails Console?

可能是我的设置有问题:irb(main):001:0>truncate("Onceuponatimeinaworldfarfaraway",:length=>17)NoMethodError:undefinedmethod`truncate'formain:Objectfrom(irb):1from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in`start'from/usr/lib64/ruby/gems/1.9.1/gems/railties-3.2.8/lib/ra

ruby-on-rails - rails : why is calling to_a on a string not valid in a rake task?

我正在尝试解密一组用于数据库迁移的密码。我有一些旧的Rails代码(实际上是一个Runner脚本)可以很好地解密它们。但是将相同的代码放入Rake任务会导致任务失败,并显示...未定义的方法`to_a'for"secretkey":String...为什么在字符串上调用to_a在Rake任务中无效,但在Runner脚本中却完全有效?require'openssl'KEY='secretkey'namespace:importdotask:users=>:environmentdodefdecrypt_password(pw)cipher=OpenSSL::Cipher::Cipher.

ruby-on-rails - Rails4 : Why resque worker is not picking up jobs

我在我的Rails4应用程序中使用resque和resque_scheduler。我的应用程序正在为resque提供一些工作,但工作人员没有在处理这些工作。reque-web显示没有失败。我已经通过运行开始resqueworkerQUEUE=kqueuerakeenvironmentresque:work我的rails控制台2.0.0p353:006>Resque.info=>{:pending=>0,:processed=>0,:queues=>0,:workers=>1,:working=>0,:failed=>0,:servers=>["redis://localhost:637