安装和使用act-as-taggable-on

时间:2021-07-11 11:06:00

This is going to be a really dumb question, I just know it, but I'm going to ask anyways because it's driving me crazy.

这将是一个非常愚蠢的问题,我只知道它,但无论如何我会问,因为它让我发疯。

How do I get acts-as-taggable-on to work?

我如何使作为标签的行为起作用?

I installed it as a gem with gem install acts-as-taggable-on because I can't ever seem to get installing plugins to work, but that's a whole other batch of questions that are all probably really dumb. Anyways, no problems there, it installed correctly.

我把它作为gem安装了gem install act-as-taggable-on因为我似乎无法安装插件才能工作,但这是另外一批可能真的很愚蠢的问题。无论如何,没有问题,它安装正确。

I did ruby script/generate acts_as_taggable_on_migration and rake db:migrate, again no problems.

我做了ruby脚本/生成acts_as_taggable_on_migration和rake db:migrate,再次没有问题。

I added acts_as_taggable to the model I want to use tags with, started up the server and then loaded the index for the model just to see if what I've got so far is working and got the following error: undefined local variable or method `acts_as_taggable' for #.

我将acts_as_taggable添加到我想要使用标签的模型中,启动服务器然后加载模型的索引,看看我到目前为止所做的是否正常工作并得到以下错误:未定义的局部变量或方法` acts_as_taggable'代表#。

I figure that just means I need to do something like require 'acts-as-taggable-on' to my model's file because that's typically what's necessary for gems. So I did that hit refresh and got uninitialized constant ActiveRecord::VERSION. I'm not even going to pretend to begin to know what that means went wrong.

我认为这只意味着我需要对我的模型文件执行类似需要'act-as-taggable-on'的操作,因为这通常是宝石所必需的。所以我做了那个命中刷新并获得了未初始化的常量ActiveRecord :: VERSION。我甚至不会假装开始知道这意味着什么出错了。

Did I go wrong somewhere or there something else I need to do. The installation instructions seem to me like they just assume you generally know what you're doing and don't even begin to explain what to do when things go wrong.

我在某处或其他地方出错了我需要做的事情。在我看来,安装说明就像他们只是假设你一般都知道自己在做什么,甚至没有开始解释当出现问题时该怎么做。

3 个解决方案

#1


1  

Did you try to define your gem dependencies in config/environment.rb (Rails 2.3):

您是否尝试在config / environment.rb(Rails 2.3)中定义gem依赖项:

Rails::Initializer.run do |config|
  #...
  config.gem 'acts-as-taggable-on'
  #...
end

Or in Gemfile for Rails 3 or if you use already Bundler with rails 2.3:

或者在Gemfile for Rails 3中,或者如果你已经将Bundler与rails 2.3一起使用:

gem 'acts-as-taggable-on'

This should make the require 'acts-as-taggable-on' unnecessary

这应该使得'require-as-taggable-on'不必要

#2


1  

Maybe following the installation here can help.

也许在这里安装后可以提供帮助。

For example you don't need to:

例如,您不需要:

require 'acts-as-taggable-on'

but:

class User < ActiveRecord::Base
  acts_as_taggable
end

Otherwise you need to post more details about the error.

否则,您需要发布有关错误的更多详细信息。

#3


1  

I installed acts-as-taggable-on for my app through github. If you want to try that method instead of the gem, you can read my this post that explains my experience: http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with-tags/

我通过github为我的应用安装了act-as-taggable-on。如果你想尝试那种方法而不是gem,你可以阅读我的帖子来解释我的经历:http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with标签都有效/

#1


1  

Did you try to define your gem dependencies in config/environment.rb (Rails 2.3):

您是否尝试在config / environment.rb(Rails 2.3)中定义gem依赖项:

Rails::Initializer.run do |config|
  #...
  config.gem 'acts-as-taggable-on'
  #...
end

Or in Gemfile for Rails 3 or if you use already Bundler with rails 2.3:

或者在Gemfile for Rails 3中,或者如果你已经将Bundler与rails 2.3一起使用:

gem 'acts-as-taggable-on'

This should make the require 'acts-as-taggable-on' unnecessary

这应该使得'require-as-taggable-on'不必要

#2


1  

Maybe following the installation here can help.

也许在这里安装后可以提供帮助。

For example you don't need to:

例如,您不需要:

require 'acts-as-taggable-on'

but:

class User < ActiveRecord::Base
  acts_as_taggable
end

Otherwise you need to post more details about the error.

否则,您需要发布有关错误的更多详细信息。

#3


1  

I installed acts-as-taggable-on for my app through github. If you want to try that method instead of the gem, you can read my this post that explains my experience: http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with-tags/

我通过github为我的应用安装了act-as-taggable-on。如果你想尝试那种方法而不是gem,你可以阅读我的帖子来解释我的经历:http://blog.mediummassage.com/2010/04/27/creating-categories-in-the-store-with标签都有效/