在 Rails 中使用 gem——需要“gemname”;结果找不到文件
我一直在尝试将 'twitter_oauth' gem 与我的 Rails 应用程序一起使用,但每当我有 require 'twitter_oauth'
时,我都会收到“没有要加载的此类文件”错误。
我已经在 Gemfile 中列出了 twitter_oauth gem,当我尝试在 Rails 控制台中启动一个新的 Client 实例时,即使我没有首先输入 require 'twitter_oauth'.我什至制作了一个测试 ruby 文件,其中只有:
require 'twitter_oauth'
client = TwitterOAuth::Client.new
if client != nil
puts "It worked!"
else
puts "It did not work"
end
并且运行该文件也有效。
我也尝试过将 require 'rubygems' 也放入其中,并且尝试将 require 'twitter_oauth' 代码放入 config/application.rb 文件中。
其他gems工作正常,例如'will_paginate'(在我的rails应用程序中,在rails控制台和irb中)
另外,有趣的是,当我在irb中时,需要'twitter_oauth'也会导致错误,但是当我运行这个简单的时候ruby程序,运行良好。
I've been trying to use the 'twitter_oauth' gem with my rails application but whenever I have require 'twitter_oauth'
, I get a "No such file to load" error.
I've already listed the twitter_oauth gem in my Gemfile, and when I try to initiate a new instance of Client in the rails console, it works perfectly fine, even when I don't first enter require 'twitter_oauth'
. I even made a test ruby file where all it had was:
require 'twitter_oauth'
client = TwitterOAuth::Client.new
if client != nil
puts "It worked!"
else
puts "It did not work"
end
And running that file worked also.
I've tried putting require 'rubygems' also and I've tried placing the require 'twitter_oauth' code in the config/application.rb file.
Other gems work fine, such as 'will_paginate' (in my rails application, in rails console and in irb)
Also, interestingly enough, when I'm in irb, require 'twitter_oauth' results in an error too but when I run that simple ruby program, it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚安装了这个 gem 并制作了一个新的 Rails 3 应用程序,将其添加到 Gemfile 中,我可以从“rails 控制台”以及运行“rails 服务器”时从应用程序内以及从“irb”访问它。您确定您输入的宝石名称正确吗?我输入了几次“twitter_oath”而不是“twitter_oauth”,这让我自己很困惑……
你有最新的 rubygems 吗?也许可以尝试:
你使用的是 Rails 3 吗?什么操作系统和你用的是红宝石吗?
I just installed this gem and made a new rails 3 app, added it to the Gemfile and I can access it fine from 'rails console' and from within the app when running 'rails server' and also from 'irb'. Are you sure you've typed the gem name correctly? I confused myself by typing 'twitter_oath' a few times and not 'twitter_oauth'...
Have you got the latest rubygems? perhaps try:
Are you using rails 3? What OS & ruby are you using?