【问题标题】:Using Gems with Ruby On Rails: Undefined method?在 Ruby On Rails 中使用 Gems:未定义的方法?
【发布时间】:2011-03-17 23:39:58
【问题描述】:

这个时髦的验证码可以提问而不是显示图片。您可以在textcaptcha.com 阅读有关它的信息。反正。我想将它与 Ruby on Rails 一起使用。一位名叫 Matt Hutchinson 的开发人员编写了一个 Gem,用于轻松连接到 API。他有一个set of instructions next to his source files on github。无论如何,它看起来很简单,但在尝试实现它时,我每次都会遇到这个错误:

undefined method `acts_as_textcaptcha' for #<Class:0x104098508>
Rails.root: /Users/cory/Documents/Learning/RoR/dpt

Application Trace | Framework Trace | Full Trace
app/models/citation.rb:20
app/controllers/citations_controller.rb:29:in `new'

我的问题的根源与这个特定的 gem 的关系不大,而与 gem 的工作原理有更多的关系。我已经安装了 gem,然后将它捆绑在我的 rails 应用程序中,它应该可以访问(据我了解)。我在 gemfile.rbgemfile.lock 中看到了对 gem 的引用,但它一次又一次地告诉我我正在使用未定义的方法。

gem 应该为我定义方法,不是吗?还是我必须手动执行一些操作?

如果有任何其他有用的信息,请告诉我,谢谢!

【问题讨论】:

  • 有些变化不会被自动注意到,即使在development 环境中也是如此;对于这些更改,您需要重新启动服务器。这可能是其中之一?

标签: ruby-on-rails ruby rubygems captcha


【解决方案1】:

嗯,天哪。它现在正在工作。可能是我重新启动了服务器,但我并不肯定。我所做的是安装 RubyMine 以查看是否可以使用它的调试器,这样做需要我通过那里运行捆绑安装(它选择了一些依赖项的一些不同版本),并停止我的其他 webrick 服务器,以运行一个通过 RubyMine 控制台。我这样做了,它给了我错误,当我回到我的其他安装程序时它工作了!? 无论如何,我已经解决了我的问题,但如果有人看到这个,这些是我目前的宝石:

$ bundle install
Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.0) 
Using builder (2.1.2) 
Using i18n (0.4.2) 
Using activemodel (3.0.0) 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.13) 
Using rack-test (0.5.7) 
Using tzinfo (0.3.24) 
Using actionpack (3.0.0) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.9) 
Using mail (2.2.15) 
Using actionmailer (3.0.0) 
Using arel (1.0.1) 
Using activerecord (3.0.0) 
Using activeresource (3.0.0) 
Using bcrypt-ruby (2.1.4) 
Using acts_as_textcaptcha (2.2.0) 
Using bundler (1.0.10) 
Using thor (0.14.6) 
Using railties (3.0.0) 
Using rails (3.0.0) 
Using sqlite3-ruby (1.2.5) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

谢谢大家! 但是,如果您尝试这样做,请按照建议先尝试重新启动服务器,我希望我知道这是否可行:D

【讨论】:

  • 我真的认为只需重新启动本地服务器就可以了。我对安装 gems 不是很熟悉。好吧,希望这是对其他忘记的人的一个很好的提醒。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-22
  • 2016-02-17
  • 1970-01-01
  • 2014-09-21
  • 1970-01-01
相关资源
最近更新 更多