草庐IT

fcatch-undefined-behavior

全部标签

ruby-on-rails - rails : Undefined method `truncate' in model

我的模型中有以下方法可以裁剪记录的描述,但由于未知原因截断方法不起作用:defcropped_descriptionnb_words_max=500ifdescription.length>nb_words_maxtruncate(description,:length=>nb_words_max,:separator=>'')+"..."elsedescriptionendend有人看到我做错了什么吗?谢谢。 最佳答案 你用错了,你应该在String上调用这个方法。参见truncate的签名。使用:ifdescription.le

ruby-on-rails - rails : Attr accessor undefined method in the setter

我在用户模型中有这行代码:attr_accessor:birthdate在同一个模型中,我有一个尝试通过这样做来设置生日的方法:self.birthdate=mydate其中mydate是一个Date对象。我收到此错误:undefinedmethodbirthdate='为什么会这样?attr_accessor不是创建了setter和getter吗? 最佳答案 让我猜猜,您是从类方法中调用setter的,对吧?classFooattr_accessor:bardefset_barvalself.bar=val#`self`isani

ruby-on-rails - Rails 3 +Devise + RSpec : undefined method 'visit'

我遇到了一个奇怪的问题。我以前从未使用过Devisegem。所以,我尝试编写简单的RSpec测试:require'spec_helper'describe"Admins"dobefore(:each)do@email="test@test.ru"user=FactoryGirl.create(:user,:email=>@email)enddescribe"signin/out"dodescribe"success"doit"shouldsignauserinandout"dovisitnew_user_session_pathendendendend我收到这样的错误:1)Admins

ruby - 加载路线 : TypeError: undefined is not a function 时出错

我真的希望emberjs团队的人能读到这篇文章。我是一位非常有经验的程序员,精通多种语言。&就AFAember而言,它不是学习曲线,我也不觉得缺乏知识和教程,相反,我认为是框架和开发环境资源的不断变化消耗了大量的时间、精力和精力,当各种SO问题和谷歌引用不同/旧版本的框架时,试图找出问题所在。我发现这里需要某种配置图表,说明什么与什么一起工作以及如何配置您的开发环境。有很多答案不一定指向正确的方向,这很难描述,但我有点感觉文档在框架向前运行时落后了。我经历了所有JoséMota很棒的教程,在构建实际书签应用程序的最后阶段,我遇到了很多问题,以至于学习emberjs不是主要问题,而是它周

ruby-on-rails - 从 Rails 4.1.4 更新到 4.2.0 后,AR CollectionProxy 上的 "first!"引发 "undefined method [] for nil"

我开始从Rails4.1.4升级到Rails4.2.0。好像是第一!不再支持某些事件记录关联。first!(在ActiveRecord::Associations::CollectionProxy上)发生了什么导致它现在失败?如何修复该行为,使其像在4.1.4中一样工作?rails4.1:(byebug)user.organization.registration_codes#]>(byebug)user.organization.registration_codes.first!#rails4.2:(byebug)user.organization.registration_code

ruby-on-rails - Rails 控制台错误 : undefined method `each' for nil:NilClass (NoMethodError)

在我的Rails应用程序的根目录中运行railsconsole的任何尝试都会产生以下错误:undefinedmethod`each'fornil:NilClass(NoMethodError)完整的堆栈跟踪:/Users/gnerkus/.rvm/gems/ruby-2.2.3@rails-experiments/gems/railties-5.0.0.beta1.1/lib/rails/railtie.rb:245:in`each_registered_block':undefinedmethod`each'fornil:NilClass(NoMethodError)from/Use

ruby - 无法使用 facebook 进行身份验证 : undefined method 'web_server' for OAuth2?

试图让用户登录/注册Twitter和Facebook。Twitter没有问题,但Facebook的策略不同。undefinedmethod`web_server'for#跟踪显示oa-oauth(0.0.1)lib/omniauth/strategies/oauth2.rb:18:in`request_phase'oa-oauth(0.0.1)lib/omniauth/strategies/facebook.rb:28:in`request_phase'oa-core(0.0.5)lib/omniauth/strategy.rb:25:in`call!'oa-core(0.0.5)li

ruby-on-rails - 无方法错误 : undefined method `email' for nil:NilClass : can't send email with devise/sendgrid(Rails 3. 2)

我正在尝试将actionmailer与sendgrid一起使用,并在Rails3.2上进行设计。我浏览了很多关于SO的问题,比如用sendmail替换smtp,创建一个config/email.yml我没有一个)和更多的想法,但没有任何效果。我一定是遗漏了什么。电子邮件似乎不会在开发或生产中发送。(sendgrid不报告任何已发送的电子邮件,并且我在“手动测试”中检查过我从未收到过电子邮件)。运行Heroku控制台,我刚刚设法获得以下信息:NoMethodError:undefinedmethod`email'fornil:NilClassonthenotifier.rbfile::m

ruby-on-rails - rspec 用户测试给出 "undefined local variable or method ` confirmed_at' "

我的rspec测试给了我NameError:undefinedlocalvariableormethod`confirmed_at'for#我的用户规范是:require'spec_helper'describeUserdobefore(:each)do@user=Factory(:user)end#Factorywillmakesurethatinthefutureifattributesareaddedthetestsbelowdon'tbreak#JustaslongastheFactoryisupdatedforthenewattributesasappropriate.con

c++ - 使用 Libc++ undefined reference 使用 Clang 进行编译

第一对太长了,无法引用。当我尝试使用来自SVN的clang和libc++编译clang++-stdlib=libc++../main.cc...时出现此错误。error:undefinedreferenceto'typeinfoforcharconst*'error:undefinedreferenceto'__cxa_allocate_exception'error:undefinedreferenceto'__cxa_throw'/tmp/cc-pbn00y.o:../main.cc:functionstd::__1::deque>::__add_back_capacity():e