第一次调用控制器,定义了常量,第二次调用,“未初始化的常量Oauth"? [英] First Call to a Controller, Constant is defined, Second call, "uninitialized constant Oauth"?

查看:109
本文介绍了第一次调用控制器,定义了常量,第二次调用,“未初始化的常量Oauth"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使OAuth gem与Rails 3一起使用,并且遇到了这个奇怪的问题...(与gem无关,我想我以前也曾遇到过此问题)

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)

我有一个名为"OauthTestController"的控制器和一个名为"ConsumerToken"的模型.该模型如下所示.

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

当我转到"/oauth_test/twitter"时,它会加载Oauth::Models::Consumers::Token模块,并且我可以毫无问题地连接到twitter.但是第二次尝试(只是刷新/oauth_test/twitter网址),它给了我这个错误:

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?

推荐答案

尝试使用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.

这篇关于第一次调用控制器,定义了常量,第二次调用,“未初始化的常量Oauth"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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