宝石中未定义的局部变量或方法`acts_as_taggable'

时间:2021-02-11 23:48:39

I'm working on converting a plugin to a gem. In one of the models I'm using acts_as_taggable_on, and it looks like this

我正在努力将插件转换为gem。在其中一个模型中,我使用的是acts_as_taggable_on,它看起来像这样

class BlogPost < ActiveRecord::Base
  acts_as_taggable
  ....
end

However, I get this error when I run it:

但是,当我运行它时,我收到此错误:

 undefined local variable or method `acts_as_taggable' for #<Class:0x000000060799b8>

and the stack trace looks like this:

并且堆栈跟踪如下所示:

activerecord (3.1.0) lib/active_record/base.rb:1082:in `method_missing'
test_gem (0.1.0) app/models/blog_post.rb:28:in `<class:BlogPost>'
test_gem (0.1.0) app/models/blog_post.rb:2:in `<top (required)>'

The acts_as_taggable gem is included in my gemspec file and is installed on the system.

acts_as_taggable gem包含在我的gemspec文件中,并安装在系统上。

gem install acts-as-taggable-on
Successfully installed acts-as-taggable-on-2.1.1
1 gem installed
Installing ri documentation for acts-as-taggable-on-2.1.1...
Installing RDoc documentation for acts-as-taggable-on-2.1.1...

I have no idea what could be wrong - please help me out

我不知道会出现什么问题 - 请帮帮我

3 个解决方案

#1


20  

I had the same issue. I restarted my server and it worked fine after

我遇到过同样的问题。我重新启动了我的服务器,之后运行良好

#2


4  

none of above answers works for me, what I did was put :

以上答案都不适合我,我所做的是:

 require 'acts-as-taggable-on'

in the beginning the model where I'm using the gem :)

在我开始使用宝石的模型:)

#3


2  

Have you put the following in you Gemfile:

你把以下内容放在Gemfile中:

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

then

然后

bundle install

#1


20  

I had the same issue. I restarted my server and it worked fine after

我遇到过同样的问题。我重新启动了我的服务器,之后运行良好

#2


4  

none of above answers works for me, what I did was put :

以上答案都不适合我,我所做的是:

 require 'acts-as-taggable-on'

in the beginning the model where I'm using the gem :)

在我开始使用宝石的模型:)

#3


2  

Have you put the following in you Gemfile:

你把以下内容放在Gemfile中:

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

then

然后

bundle install