草庐IT

handler+message【消息机制】

全部标签

ruby-on-rails - RSpec:多次期待一条消息但参数不同

我目前对连续调用的模拟设置了一些期望:规范:@my_mock=mock("a_mock")@options1={:some=>"option"}@options2={:some_other=>"option"}@first_param=mock("first_param")@my_mock.should_receive(:a_message).with(@first_param,@options1)@my_mock.should_receive(:a_message).with(@first_param,@options2)但是,我得到以下信息:Mock"a_mock"received

ruby - 如何使用 RSpec should_receive 忽略额外的消息?

规范:beforedoLogger.should_receive(:write).with'Logmessage1'endit'works'doget'/'endSinatra应用程序:get'/'Logger.write('Logmessage1')Logger.write('Logmessage2')end由于“日志消息2”,此规范失败。如何告诉RSpec忽略任何其他消息,只测试预期的消息? 最佳答案 您需要在消息预期之前对将接收消息的方法进行stub。#RSpecstubmethodisdeprecatedinRSpec3,而

ruby-on-rails - { "error": { "message": "Missing client_id parameter.", "type": "OAuthException", "code": 101 } }

我正在关注RyanBatesScreenCast#360Facebook身份验证...当我到达点击链接登录facebook的部分时,我得到一个{"error":{"message":"Missingclient_idparameter.","type":"OAuthException","code":101}}我尝试像之前所说的那样重新启动服务器我正在拔头发试图弄清楚这一点我在facebook开发页面上的网站url是正确的我已经按照他的步骤数百次 最佳答案 可能是你没有为FACEBOOK_KEY和FACEBOOK_SECRET设置e

ruby - 如何使 Rails 中的 Flash 消息超时

我目前有标准的flash消息和用于成功/失败等的设计gem。我已经添加了通过关闭类使用一些Bootstrap功能手动关闭消息的选项。下面显示了一个小片段。{×"flash_#{name}"%>}我希望有一个选项来创建一个超时期限,警报消息将在5秒后关闭。不确定是否有在Rails中执行此操作的简单方法。谢谢 最佳答案 如果你在同一个页面中加载了jQuery,这对你有用×"flash_#{name}"%>$(document).ready(function(){setTimeout(function(){$('#fl

ruby-on-rails - 国际化 : error message localization for particular model

我可以为每个验证本地化错误消息,但我如何为特定模型创建错误。普通语言环境看起来像这样:en:mongoid:errors:messages:taken:"Itisalreadytaken"但我想为user模型更改消息:en:mongoid:errors:messages:taken:"Itisalreadytaken"user:taken:"Itisalreadytaken.%{link_to'Rememberpassword',reset_password_path'}" 最佳答案 试试这个:en:mongoid:errors:m

ruby - 为什么我将鼠标悬停在 Ruby 文件的任何单词上时会收到弹出消息?

如果我将鼠标悬停在Ruby文件的任何单词上,我会收到一条工具提示消息。该弹出消息的屏幕截图位于popupmessage.cat~/.gvimrc返回:function!SyntaxBalloon()letsynID=synID(v:beval_lnum,v:beval_col,0)letgroupID=synIDtrans(synID)letname=synIDattr(synID,"name")letgroup=synIDattr(groupID,"name")returnname."\n".groupendfunctionsetballoonexpr=SyntaxBalloon()

ruby-on-rails - rails 3 : how to generate custom error message from failed validation

我正在使用validates:feed_id,presence:true,uniqueness:true我应该如何生成自定义错误消息以指定用户已经订阅了此提要(feed_id)字段重复我知道我可以只做validate_uniqueness_of但它会不必要地使代码困惑。如果唯一性验证失败,我该如何传递特定的错误消息?? 最佳答案 使用键message和期望的消息作为值而不是true放置一个散列:validates:feed_id,presence:true,uniqueness:{message:"alreadysubscribed

ruby-on-rails - 来自 Rails 4 中 Controller 的带有 html_safe 的 Flash 消息(安全版本)

在我的Controller中,我有以下代码:format.html{redirect_tonew_customer_url,notice:%Q[Acustomeralreadyexistswithwiththisshoppingid.Editthiscustomer#{view_context.link_to("here",edit_customer_url(@duplicate))}.].html_safe我希望能够在Flash消息中包含一个链接,因此(如您所见)我调用html_safe来取消转义该字符串。然而,从Rails4.1开始,这似乎有了不同的处理方式。(参见here和her

ruby - 如何避免来自 RubyGems 的弃用消息?

在gemupdate--system之后,当我做一些与ruby​​gems相关的事情时,我收到这条消息:NOTE:Gem::Specification#default_executable=isdeprecatedwithnoreplacement.Itwillberemovedonorafter2011-10-01.Gem::Specification#default_executable=calledfrom/usr/lib/ruby/gems/1.8/specifications/rubygems-update-1.7.2.gemspec:11.如何避免?我尝试删除ruby​​g

ruby-on-rails - 在 Rails 3.2 中使用 "error_messages"? (引发 "undefined method"错误)

我在Rails3.2功能测试中遇到以下错误:ActionView::Template::Error:undefinedmethod`error_messages'for#产生错误的View代码:#problematiccode这是我的Controller中调用上述View代码的代码:render:action=>"edit",:status=>:bad_request这是我正在运行的测试:test"updateaprogramwithabadrequest"doput:update,:id=>programs(:traditional).to_param,:program=>{:min