【发布时间】:2017-07-01 09:33:36
【问题描述】:
我创建了一个 rails 应用程序并添加了acts-as-taggable-on gem,运行 rake db:migrate 并将该字段添加到 Article.rb。我似乎在使用 rail 5.1 应用程序时遇到了这个错误。我不知道它是什么。
宝石文件
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)>'
【问题讨论】:
-
在将 gem 添加到 Gemfile 后,您是否运行了
bundle install?您是否重新启动了字符串和应用程序?
标签: ruby-on-rails ruby acts-as-taggable-on