简体   繁体   English

在Ruby On Rails中使用Gems:未定义的方法?

[英]Using Gems with Ruby On Rails: Undefined method?

There's this snazzy captcha that asks questions rather than displaying pictures. 有一个时髦的验证码会问问题而不是显示图片。 You can read about it at textcaptcha.com . 您可以在textcaptcha.com上阅读有关它的信息 Anyway. 无论如何。 I want to use that with Ruby on Rails. 我想在Ruby on Rails中使用它。 A developer by the name of Matt Hutchinson wrote a Gem for easily connecting to the API. 一位名叫Matt Hutchinson的开发人员编写了Gem,可以轻松连接到API。 He has a set of instructions next to his source files on github . 在github上的源文件旁边有一组说明 Anyway, It looks pretty simple but in trying to implement it I get this error every time: 无论如何,它看起来非常简单,但是在尝试实现它时,每次都会出现此错误:

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'

The root of my question has a bit less to do with this specific gem, and a little more with how gems work. 我的问题的根源与该特定宝石无关,而与宝石的工作原理有关。 I've installed the gem, and then bundled it inside of my rails app, it should be accessible (as I understand it). 我已经安装了gem,然后将其捆绑在我的rails应用程序中,应该可以访问(据我了解)。 I see references to the gem in the gemfile.rb and the gemfile.lock , but again and again it tells me I'm using and undefined method. 我在gemfile.rbgemfile.lock看到了对gem的引用,但是一次又一次地告诉我我正在使用undefined方法。

The gem should be defining the method for me, should it not? 宝石应该为我定义方法,不是吗? Or is there something that I manually have to do? 还是我需要手动执行某些操作?

Just let me know if there is any other info that would be helpful, thanks! 请让我知道是否还有其他有用的信息,谢谢!

Well, jeez. 好吧,老兄 It's working now. 现在正在工作。 It could be that I restarted the server, but I'm not positive. 可能是我重新启动了服务器,但我并不满意。 What I did was installed RubyMine to see if I could use it's debugger, in doing so it required that I run the bundle install (it chose some different versions of some dependancies) through there, and also stop my other webrick server, to run the one through the RubyMine console. 我所做的是安装RubyMine来查看是否可以使用它的调试器,这样做需要在那儿运行bundle install(它选择了一些依赖关系的不同版本),并停止其他webrick服务器来运行一个通过RubyMine控制台。 I did so, it gave me errors, when when I went back to my other installer it worked!? 我这样做了,当我回到其他安装程序时,它给我带来了错误! Anyway, I've got my question resolved, but in the event that anyone looks this up, these are my current gems: 无论如何,我的问题已经解决,但是如果有人找了,这是我目前的瑰宝:

$ 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.

Thanks all! 谢谢大家! But if you are trying this, do try restarting the server first as suggested, I wish I knew if that would have worked :D 但是,如果您要尝试此操作,请按照建议先尝试重新启动服务器,但愿我知道那是否可行:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM