programing tip

NoMethodError : 레이크 11로 업그레이드 한 후 정의되지 않은 메소드 'last_comment'

itbloger 2020. 7. 4. 11:14
반응형

NoMethodError : 레이크 11로 업그레이드 한 후 정의되지 않은 메소드 'last_comment'


어떤 rake작업을 실행할 때 나는 얻는다 :

NoMethodError : 정의되지 않은 메소드 'last_comment'

그 후에 bundle update새 버전의 레이크 버전 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 : # <Rake :: Application : 0x007ff0cf37be38>에 대해 정의되지 않은 메소드 'last_comment'

버전

  • 레일 3.2.11
  • 레이크 11.0.1

레이크 11.0.1 제거last_comment 방법 어느레일 2.3rspec-core (<3.4.4)가 사용됩니다. 따라서 패치가 출시 될 때까지 Gemfile에서 이전 버전으로 갈퀴를 고정해야합니다.

gem 'rake', '< 11.0'

그때:

$ bundle update
$ grep rake Gemfile.lock 
      rake
      rake (>= 0.8.7)
    rake (10.5.0)
      rake
  rake (< 11.0)

우리는 지금 여전히 last_comment방법을 가지고 있으며 rake작업이 다시 작동 하는 레이크 10.5.0을 사용 하고 있습니다.

업데이트 : 이것은 rspec에서 수정되었으므로 rspec을 업데이트하면됩니다.


Rails 빠른 수정은 ./Rakefile앱 폴더에서 편집 할 수 있습니다.

호출하기 전에 다음 행을 추가하십시오 Rails.application.load_tasks.

module TempFixForRakeLastComment
  def last_comment
    last_description
  end 
end
Rake::Application.send :include, TempFixForRakeLastComment

그래서 전체 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

최신 Rspec보석으로 업데이트 하면 작동합니다.

bundle update rspec-rails


그냥 보석을 업그레이드하십시오 rspec-rails

지금: gem 'rspec-rails', '~> 3.5', '>= 3.5.2'

안아!


이것은 이미 해결 된 레이크 문제입니다 .

@ 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.

Any Rake < v11.0.1 or > v11.0.1 and < v12 will work but this is still a work around and should also be avoided; ideally you'll be able to stay with the times.

Since last_comment is being deprecated the dependency itself should be upgraded. In my case it was rspec-core which incidentally only fixed this in v3.4.4.

The Fix

Upgrade your dependency to a version which doesn't call last_comment but calls last_description instead. Its probably rspec and upgrading rspec-core to 3.4.4 or greater will fix it. rspec-core < 3.4.4 calls 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 :)

참고URL : https://stackoverflow.com/questions/35893584/nomethoderror-undefined-method-last-comment-after-upgrading-to-rake-11

반응형