Ruby-on-rails NoMethodError:升级到 rake 11 后未定义方法“last_comment”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35893584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoMethodError: undefined method `last_comment' after upgrading to rake 11
提问by Kris
When running any raketask I get:
运行任何rake任务时,我得到:
NoMethodError: undefined method `last_comment' for
NoMethodError:未定义方法“last_comment”
This was after bundle updatewhich pulled in the new version of rake, version 11.0.1.
这是之后bundle update拉入新版本的 rake, version 11.0.1。
$ grep rake Gemfile.lock
rake
rake (>= 0.8.7)
rake (11.0.1)
rake
$ bundle update
$ bundle exec rake db:drop # any rake task
NoMethodError: undefined method `last_comment' for #< Rake::Application:0x007ff0cf37be38>
NoMethodError: #<Rake::Application:0x007ff0cf37be38> 的未定义方法 `last_comment'
Versions
版本
- Rails 3.2.11
- Rake 11.0.1
- 导轨 3.2.11
- 耙子 11.0.1
回答by Kris
Rake 11.0.1 removesthe last_commentmethod which Rails 2.3rspec-core (< 3.4.4) uses. Therefore until/if a patch is released we need to pin rake to an older version in Gemfile:
耙11.0.1移除的last_comment方法,该方法导轨 2.3rspec-core (< 3.4.4) 使用。因此,直到/如果发布补丁,我们需要将 rake 固定到 Gemfile 中的旧版本:
gem 'rake', '< 11.0'
then:
然后:
$ bundle update
$ grep rake Gemfile.lock
rake
rake (>= 0.8.7)
rake (10.5.0)
rake
rake (< 11.0)
We are now using rake 10.5.0 which still has the last_commentmethod and our raketasks will work again.
我们现在使用 rake 10.5.0,它仍然有这个last_comment方法,我们的rake任务将再次工作。
UPDATE: This has now been fixed in rspec, so the only thing necessary should be updating rspec.
更新:这现在已在 rspec 中修复,因此唯一需要的应该是更新 rspec。
回答by equivalent8
in Rails quick fix can be edit ./Rakefile(in your app folder)
在 Rails 快速修复中可以编辑./Rakefile(在您的应用程序文件夹中)
and add these lines before calling Rails.application.load_tasks:
并在调用之前添加这些行Rails.application.load_tasks:
module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment
so entire Rakefilemight look like
所以整个Rakefile可能看起来像
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'resque/tasks'
+ # temp fix for NoMethodError: undefined method `last_comment'
+ # remove when fixed in Rake 11.x
+ module TempFixForRakeLastComment
+ def last_comment
+ last_description
+ end
+ end
+ Rake::Application.send :include, TempFixForRakeLastComment
+ ### end of temfix
+
task "resque:preload" => :environment
Rails.application.load_tasks
回答by Gal Bracha
Update to the latest Rspecgem does the work:
更新到最新的Rspecgem 可以工作:
bundle update rspec-rails
bundle update rspec-rails
回答by EderCosta
Just upgrade the gem rspec-rails
只需升级宝石 rspec-rails
Now: gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
现在: gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
hugs!
拥抱!
回答by yekta
This is an issue in rakethat has been addressed already.
这是rake中已经解决的问题。
The answer by @equivalent8 is a monkey patch and should be avoided.
@equivalent8 的答案是猴子补丁,应该避免。
As @Kris points out, this is an issue isolated to rake 11.0.1. Since @Kris has posted his answer there are new versions of Rake available and ideally you would be able to stay with the times and not be pinned to an old version of rake. Believe me, I've been there and its not a good idea if you can help it. Also this is not an issue with Rails 2.3 or any version of rails.
正如@Kris 指出的那样,这是一个与rake 11.0.1. 由于@Kris 已经发布了他的答案,因此有新版本的 Rake 可用,理想情况下,您将能够与时俱进,而不会被固定在旧版本的 rake 上。相信我,我去过那里,如果你能帮忙,这不是一个好主意。这也不是 Rails 2.3 或任何版本的 rails 的问题。
Any Rake < v11.0.1or > v11.0.1 and < v12will work but this is still a work around and should also be avoided; ideally you'll?be able to stay with the times.
任何 Rake < v11.0.1or> v11.0.1 and < v12都可以工作,但这仍然是一种解决方法,也应该避免;理想情况下,您将能够与时俱进。
Since last_commentis being deprecated the dependency itself should be upgraded. In my case it was rspec-corewhich incidentally only fixed this in v3.4.4.
由于last_comment已被弃用,因此应升级依赖项本身。就我而言,它rspec-core只是在v3.4.4 中顺便修复了这个问题。
The Fix
修复
Upgrade your dependency to a version which doesn't call last_commentbut calls last_descriptioninstead. Its probably rspecand upgrading rspec-coreto 3.4.4 or greater will fix it. rspec-core< 3.4.4 calls last_comment.
将您的依赖项升级到不调用last_comment而是调用的版本last_description。它可能rspec并升级rspec-core到 3.4.4 或更高版本将修复它。 rspec-core< 3.4.4 调用last_comment。
If your dependency doesn't have a version which doesn't call last_description, be a good citizen and submit a PR to fix it :)
如果您的依赖项没有不调用的版本,请last_description做个好公民并提交 PR 来修复它:)

