草庐IT

user-defined-functions

全部标签

ruby-on-rails - rails : Your user account isn't allowed to install to the system RubyGems

我正在运行命令bundleinstall在项目文件夹中。在某些项目文件夹中,它会产生错误,而在其他项目文件夹中,它不会产生错误。错误是:Youruseraccountisn'tallowedtoinstalltothesystemRubyGems我知道这可以通过遵循推荐的建议来解决:bundleinstall--pathvendor/bundle我的问题是为什么行为不一致? 最佳答案 在我的例子中,我按照错误消息的建议解决了问题:Youruseraccountisn'tallowedtoinstalltothesystemRubyG

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-on-rails - 如何在 Rails 中修复/调试 'expected x.rb to define X.rb'

我已经看到这个问题出现在许多不同的情况下,并希望获得在StackOverflow上修复/调试它的最佳实践。今天早上我想到了一个现实世界的例子:expectedannouncement.rbtodefineAnnouncement该类(class)在生产控制台的开发、测试和中表现良好,但在生产Mongrel中失败了。这是类(class):classAnnouncement'audio/mp3',:storage=>:s3end我想在答案中解决的问题与其说是解决这个具体问题,不如说是如何正确调试以使Rails给你一个有意义的错误,如预期的那样x.rbtodefineX.rb'通常是红色的鲱

ruby Mechanize : user agents?

Mechanize中有多少用户代理?是否有所有用户代理选项的便捷列表? 最佳答案 是的。看https://github.com/sparklemotion/mechanize/blob/master/lib/mechanize.rb#L115:AGENT_ALIASES={'WindowsIE6'=>'Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1)','WindowsIE7'=>'Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;.NETCLR1.1.4

ruby-on-rails - 参数缺失或值为空 : user rails 4

当我尝试提交注册表时出现以下错误。参数缺失或值为空:用户defuser_paramsparams.require(:user).permit(:name,:email,:password,:password_confirmation)end请求如下:{"utf8"=>"✓","authenticity_token"=>"YX0+4AeWlGWJiQZgbhV9cxi6TUCoibZfwh95BrK9iCQ=","name"=>"asasa","email"=>"asasas@asas.com","password"=>"[FILTERED]","confirm_password"=>"

ruby-on-rails - rails : how to show user's "last seen at" time?

我正在使用存储current_sign_in_at和last_sign_in_at日期时间的设备。但是假设用户在一个月前登录但最后一次查看页面是在5分钟前?有什么方法可以显示(“5分钟前用户最后一次出现”)。 最佳答案 这个怎么样:创建迁移以向用户添加新字段以存储用户最后一次出现的日期和时间:railsgmigrationadd_last_seen_at_to_userslast_seen_at:datetime向您的应用程序Controller添加一个操作前回调:before_action:set_last_seen_at,if:

Ruby 基准测试模块 : meanings of "user", "system"和 "real"?

试验Ruby的基准模块...>>Benchmark.bm(7){|b|b.report('Report:'){s='';10000.times{s+='a'}}}usersystemtotalrealReport:0.1500000.0100000.160000(0.156361)“用户”、“系统”、“真实”的含义是什么? 最佳答案 这些时间与Unixtime命令或其他典型基准测试工具报告的时间相同:user:执行用户空间代码(即:您的代码)所花费的时间,system:执行内核代码所花费的时间和真实:执行代码所花费的“真实”时间(即

ruby - 如何在 initialize() 中使用 define_method

尝试在initialize中使用define_method但得到undefined_methoddefine_method。我做错了什么?classCdefinitialize(n)define_method("#{n}"){puts"somemethod#{n}"}endendC.new("abc")#=>NoMethodError:undefinedmethod`define_method'for# 最佳答案 我怀疑您正在寻找define_singleton_method:define_singleton_method(symb

ruby - 在 Ruby 的 define_method 中使用 yield

是否可以让yield关键字在给定define_method的block内工作?简单示例:classTestdefine_method:testdo|&b|putsb#=>#yieldendendTest.new.test{puts"Hi!"}此代码在Ruby1.8.7和1.9.0中都会产生以下错误:test.rb:4:in`test':noblockgiven(LocalJumpError)fromtest.rb:8奇怪的是bblock变量!=nil但block_given?返回false。不识别Proc对象的block是Ruby的故意行为吗?编辑:向Beerlington的回答致意:

ruby-on-rails - 工厂未注册 : user

我正在学习MichalHartlsRails教程第7章。我已经安装了Factorygirlgem。我在运行测试时不断收到此错误Failures:1)UsersControllerGET'show'shouldbesuccessfulFailure/Error:@user=FactoryGirl.create(:user)ArgumentError:Factorynotregistered:user#./spec/controllers/users_controller_spec.rb:10:in`block(3levels)in'Finishedin0.66336seconds42ex