acts_as_taggable_on Gem不适用于Rails 5

时间:2017-07-01 09:33:37

标签: ruby-on-rails ruby acts-as-taggable-on

我创建了一个rails应用程序并添加了act-as-taggable-on gem,运行了rake db:migrate并将该字段添加到Article.rb中。我似乎用轨道5.1应用程序得到这个错误。我无法弄清楚它是什么。

的Gemfile

gem 'acts-as-taggable-on', '~> 4.0'

Article.rb

class Article < ApplicationRecord
    include TheComments::Commentable

     acts_as_taggable_on :tags

        belongs_to :user

      # Denormalization methods
      # Check the documentation for information on advanced usage
        def commentable_title
        title
      end

      def commentable_url
        ['', self.class.to_s.tableize, id].join('/')
      end

      def commentable_state
        :published.to_s
      end
    end

但是我收到了这个错误:

Running via Spring preloader in process 18395
Loading development environment (Rails 5.1.2)
2.4.0-rc1 :001 > Article
NoMethodError: undefined method `acts_as_taggable_on' for Article (call 'Article.connection' to establish a connection):Class
    from app/models/article.rb:6:in `<class:Article>'
    from app/models/article.rb:1:in `<top (required)>'
    from (irb):1
2.4.0-rc1 :002 > Article
NoMethodError: undefined method `acts_as_taggable_on' for Article (call 'Article.connection' to establish a connection):Class
    from app/models/article.rb:6:in `<class:Article>'
    from app/models/article.rb:1:in `<top (required)>'

2 个答案:

答案 0 :(得分:1)

问题的原因在于gem的版本。您正在使用的gem版本不支持Rails 5.

您可以通过直接从github中提取gem来解决您的错误。 为此,只需使用gemfile中的以下代码:

gem 'acts-as-taggable-on', :git => 'https://github.com/mbleigh/acts-as-taggable-on'

答案 1 :(得分:1)

他们的版本5未提及。文档说版本4适用于Rails 4和5,这是不准确的。我将以下内容添加到我的Gemfile中并使其正常工作。 GitHub链接是我的参考点。

gem "acts-as-taggable-on", "~> 5.0"

https://github.com/mbleigh/acts-as-taggable-on/issues/866