第一次调用控制器,定义了常量,第二次调用,“未初始化常量 Oauth”?
我正在尝试让 OAuth gem 与 Rails 3 一起使用,但我遇到了这个奇怪的问题...(独立于 gem,我想我以前遇到过这个问题)
我有一个名为“OauthTestController”的控制器,以及一个名为“ConsumerToken”的模型。模型看起来像这样。
require 'oauth/models/consumers/token'
class ConsumerToken < ActiveRecord::Base
include Oauth::Models::Consumers::Token
end
当我转到“/oauth_test/twitter”时,它会加载 Oauth::Models::Consumers::Token
模块,我可以毫无问题地连接到 twitter。但是当我第二次尝试时(只需刷新 /oauth_test/twitter
url),它给了我这个错误:
NameError (uninitialized constant Oauth):
app/models/consumer_token.rb:4
app/models/twitter_token.rb:2
app/controllers/oauth_test_controller.rb:66:in `load_consumer'
这是为什么?它可能与加载路径或处于开发模式有关?
I am trying to get the OAuth gem to work with Rails 3 and I'm running into this weird problem... (independent of the gem, I think I've run into this once before)
I have a controller called "OauthTestController", and a model called "ConsumerToken". The model looks like this.
require 'oauth/models/consumers/token'
class ConsumerToken < ActiveRecord::Base
include Oauth::Models::Consumers::Token
end
When I go to "/oauth_test/twitter", it loads the Oauth::Models::Consumers::Token
module and I'm able to connect to twitter no problem. But the second time I try it (just refresh the /oauth_test/twitter
url), it gives me this error:
NameError (uninitialized constant Oauth):
app/models/consumer_token.rb:4
app/models/twitter_token.rb:2
app/controllers/oauth_test_controller.rb:66:in `load_consumer'
Why is that? It has something to do with load paths or being in development mode maybe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 require_or_load 而不是 require。这在开发过程中每次都会强制满载,有时可以帮助解决此类问题。
Try using require_or_load instead of require. That forces full load each time when in development and can sometimes help with this sort of issue.
是的,这与处于开发模式有关。在 development.rb 中设置 config.cache_classes = true 让它工作(但很痛苦)
Yeah it's something to do with being in development mode. Setting config.cache_classes = true in your development.rb get's it working (but is a pain in the ass)