jjzjj

NoMethodError

全部标签

ruby-on-rails - Rails : many to many Model, NoMethodError:未定义的方法

我被这个问题困了一段时间。这是我的模型关系。classGame:destroyhas_many:players,through::participates,:dependent=>:destroyendclassPlayer:destroyhas_many:games,through::participates,:dependent=>:destroyendclassParticipate我把它放在seed.rbPlayer.destroy_allGame.destroy_allg1=Game.create(game_name:"LOL")g2=Game.create(game_nam

ruby-on-rails - rescue_from NoMethodError

在解决这个问题时遇到问题。尝试做一个rescue_fromNoMethodError,:with=>:try_some_options但它不起作用。编辑:为了测试,我正在做一个简单的重定向deftry_some_optionsredirect_toroot_urlend编辑2:我的Controller样本。按照下面的建议添加(异常(exception))。我知道我收到错误的原因。使用Authlogic和authlogic_facebook_connect插件。当用户从facebook插件创建时,与用户关联的“MyCar”模型不会像用户在本地注册时通常创建的那样创建。由于我确实调用了用户

ruby-on-rails - ruby/rails NoMethodError?使用自定义验证方法时

我是ruby​​和rails的新手,遇到了一个相当奇怪的错误:classPersonrequire_description_presence?defrequire_description_presence?self.can_send_emailendend加注NoMethodErrorinPeopleController#indexundefinedmethod`require_description_presence?'for# 最佳答案 您应该将验证方法作为符号传递:validates_presence_of:descripti

ruby - 拯救 NameError 而不是 NoMethodError

我需要在特殊情况下捕获NameError。但我不想捕获NameError的所有子类。有办法实现吗?#ThisshallbecatchedbeginString::NotExistend.newrescueNameErrorputs'Willdosomethingwiththiserror'end#Thisshallnotbecatchedbegin#WillraiseaNoMethodErrorbutIdon'twantthisErrortobecatchedString.myattribute='value'rescueNameErrorputs'Shouldneverbecalle

ruby-on-rails - Rails 错误 "NoMethodError"- 我的第一个 ruby​​ 应用程序

我对Rails完全陌生,所以答案可能非常简单。开始了:我的页面产生了这个错误NoMethodErrorinTasks#newShowingapp/views/tasks/new.erbwhereline#3raised:undefinedmethod`tasks_path'for#Hereistheview:::Controller:classTasksController:id)enddefnew@task=Task.newend...(more)和模型:我看不出问题,但就像我说的,到目前为止我一无所知。谢谢!classTask 最佳答案

ruby - NoMethodError : undefined method ascii_only? - mail 2.5.4 和 rails 4.0 出错

请在我尝试使用mail2.5.4/rails4.0.0/ruby​​1.9.3-p125配置投递邮件时发现以下错误消息。SubscriptionMailer.send_email(Subscription.last).deliverSubscriptionLoad(0.6ms)SELECT`subscriptions`.*FROM`subscriptions`ORDERBY`subscriptions`.`id`DESCLIMIT1UserLoad(0.3ms)SELECT`users`.*FROM`users`WHERE`users`.`id`=1ORDERBY`users`.`id

ruby - 为什么 `1i.to_i` 引发 `RangeError` 而不是 `NoMethodError` ?

NoMethoError由to_i引发,仅仅是因为该类没有方法:[].to_i#>>NoMethodError(undefinedmethod`to_i'for[]:Array)果然,1i有方法to_i和to_f,所以它响应它们。但实际上这看起来非常棘手。1i.respond_to?(:to_i)#=>true1i.to_i#>>RangeError(can'tconvert0+1iintoInteger)Range类从哪里来? 最佳答案 Surelyenough,1ihasthemethod.to_iand.to_fsoitres

ruby-on-rails - 机车编辑器在尝试循环模型的条目时抛出 'NoMethodError'

因此,我正在使用Locomotive、RubyonRailsCMS及其编辑器来创建博客。在Locomotive后端,我制作了一个带有slug“帖子”的模型,其中包含一个可能的博客帖子。然后,在我的index.liquid文件中,我试图遍历模型的内容并显示全部内容。这是液体循环:{%forpostincontents.posts%}{{post.title}}{%endfor%}但它向我显示“/处无方法错误”、“nil:NilClass的未定义方法contents”。如果我从for...in循环中删除.posts,则没有错误,但循环甚至不会发生一次,自然地,因为只有contents不能循

ruby - Sinatra:NoMethodError

Wholesourcecodehere我觉得我的程序流程有逻辑错误,返回NoMethodError首先,一段导致错误的代码。"/>#ErrorTextNoMethodErrorat/profileundefinedmethod`identity'fornil:NilClassfile:journal_form.erblocation:blockinsingletonclassline:2输入标签内的代码正是错误文本中描述的代码片段。我的程序流程就是这样。用户登录如果身份验证成功,他/她将被重定向到/profile页根据他们的角色/权限,他们将在“/profile”的主要区域内看到不同的

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