我做了一個Rails應用程序,並在gem上添加了acts-as-taggable-,運行rake db:migrate並將該字段添加到Article.rb。我似乎得到了一個軌道5.1應用程序的這個錯誤。我無法弄清楚它是什麼。acts_as_taggable_on Gem不適用於Rails 5
的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)>'
你有沒有加入寶石到Gemfile文件後運行'束install'?你重新啓動了字符串和應用程序嗎? – spickermann