在Ruby On Rails中使用Gems:未定义的方法? [英] Using Gems with Ruby On Rails: Undefined method?

查看:98
本文介绍了在Ruby On Rails中使用Gems:未定义的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个时髦的验证码提出问题而不是显示图片。您可以在上阅读。无论如何。我想用Ruby on Rails。一位名叫Matt Hutchinson的开发者写了一个Gem,可以轻松连接到API。他在github上的源文件旁边有指令集。无论如何,它看起来很简单,但试图实现它我每次都会得到这个错误:

pre $ 未定义的方法`acts_as_textcaptcha'for# <类别:0x104098508>
Rails.root:/ Users / cory / Documents / Learning / RoR / dpt

应用程序跟踪|框架跟踪|完整跟踪
app / models / citation.rb:20
app / controllers / citations_controller.rb:29:在`new'

我的问题的根源与这个特定的宝石有关,还有一点与宝石的工作方式有关。我已经安装了gem,然后将它捆绑到我的rails应用程序中,它应该是可访问的(据我了解)。我在 gemfile.rb gemfile.lock 中看到对gem的引用,但它一次又一次地告诉我我使用和未定义的方法。



宝石应该为我定义方法,如果不是的话?或者有什么我手动必须做的?



请让我知道是否有任何其他信息会有帮助,谢谢!

解决方案

好吧,jeez。现在正在工作。这可能是我重新启动服务器,但我不积极。我所做的是安装了RubyMine,看看我是否可以使用它的调试器,这样做需要我通过那里运行软件包安装(它选择了一些不同版本的依赖),并停止另一台webrick服务器,运行一个通过RubyMine控制台。我这样做,它给了我错误,当我回到我的另一个安装程序,它的工作!?
无论如何,我已经解决了我的问题,但是如果有人看起来这样,这些就是我目前的宝贝:

  $ bundle install 
使用rake(0.8.7)
使用抽象(1.0.0)
使用activesupport(3.0.0)
使用构建器(2.1.2 )
使用i18n(0.4.2)
使用activemodel(3.0.0)
使用erubis(2.6.6)
使用rack(1.2.1)
使用机架安装(0.6.13)
使用机架测试(0.5.7)
使用tzinfo(0.3.24)
使用actionpack(3.0.0)
使用mime-类型(1.16)
使用polyglot(0.3.1)
使用treetop(1.4.9)
使用邮件(2.2.15)
使用actionmailer(3.0.0)$ b使用activerecord(3.0.0)
使用activeresource(3.0.0)
使用bcrypt-ruby(2.1.4)
使用acts_as_textcaptcha (2.2.0)
使用bundler(1.0.10)
使用thor(0.14.6)
使用railties(3.0.0)
使用rails(3.0.0)
使用sqlite3-ruby(1.2.5)
您的包已完成!使用`bundle show [gemname]`来查看捆绑的gem的安装位置。

谢谢大家!
但是,如果你正在尝试这样做,请尝试按照建议先重新启动服务器,我希望我知道这是否会起作用:D


There's this snazzy captcha that asks questions rather than displaying pictures. You can read about it at textcaptcha.com. Anyway. I want to use that with Ruby on Rails. A developer by the name of Matt Hutchinson wrote a Gem for easily connecting to the API. He has a set of instructions next to his source files on 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). 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.

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

这篇关于在Ruby On Rails中使用Gems:未定义的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆