applejuiceteaching
applejuiceteaching

Reputation: 1493

acts_as_taggable_on Gem not working for Rails 5

I made a rails application and added the acts-as-taggable-on gem, ran the rake db:migrate and added the field to Article.rb. I seem to get this error with a rail 5.1 app. I can't figure out what it is.

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

However I get this error:

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)>'

Upvotes: 2

Views: 1547

Answers (2)

They have version 5 which is not mentioned. The documentation says that version 4 works with both Rails 4 and 5 which is inaccurate. I added the following to my Gemfile and got it working. The GitHub link is my reference point.

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

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

Upvotes: 2

Priyesh Doshi
Priyesh Doshi

Reputation: 380

The reason for the issue is with the version of the gem. The version of the gem that you are using doesn't support Rails 5.

You can resolve your error by pulling the gem from direct from the github. For that just use below code in your gemfile:

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

Upvotes: 1

Related Questions