AuthenticationsController 中的 NoMethodError#create 未定义的方法“RandomString”对于字符串:类
我按照本教程在 devise+mongoid 中安装omniauth:
https ://github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/OmniAuth-Installation-Tutorial
我有设计1.4.5+omniauth 0.3.0+rails 3.1.0。
我的 devise.rb 中有以下信息:
config.omniauth :facebook, 'My_CONSUMER_KEY', 'MY_CONSUMER_SECRET', :scope => 'user_hometown, user_about_me, email'
在本教程中,此配置创建了一个initializers/omniauth.rb 文件。
当我从 facebook 回调回来时,我发现了这个错误:
NoMethodError in AuthenticationsController#create
undefined method `RandomString' for String:Class
app/models/user.rb:39:in `apply_trusted_services'
app/models/user.rb:23:in `apply_omniauth'
app/controllers/authentications_controller.rb:33:in `create_new_omniauth_user'
app/controllers/authentications_controller.rb:16:in `create'
我也在 lib/string_extensions.rb 中创建了一个文件,代码如下:
module StringExtensions
def self.included(base)
String.extend StringExtensions::ClassMethods
end
module ClassMethods
RAND_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"
def RandomString(len)
rand_max = RAND_CHARS.size
ret = ""
len.times{ ret << RAND_CHARS[rand(rand_max)] }
ret
end
end
end
我的问题是什么
I follow this tutorial for install omniauth in devise+mongoid:
https://github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/OmniAuth-Installation-Tutorial
I have devise 1.4.5 + omniauth 0.3.0 + rails 3.1.0.
I have in my devise.rb the next information:
config.omniauth :facebook, 'My_CONSUMER_KEY', 'MY_CONSUMER_SECRET', :scope => 'user_hometown, user_about_me, email'
In the tutorial, this configuration have that create a initializers/omniauth.rb file.
When I come back of facebook callback I catch this error:
NoMethodError in AuthenticationsController#create
undefined method `RandomString' for String:Class
app/models/user.rb:39:in `apply_trusted_services'
app/models/user.rb:23:in `apply_omniauth'
app/controllers/authentications_controller.rb:33:in `create_new_omniauth_user'
app/controllers/authentications_controller.rb:16:in `create'
I have create too a file in lib/string_extensions.rb with this code:
module StringExtensions
def self.included(base)
String.extend StringExtensions::ClassMethods
end
module ClassMethods
RAND_CHARS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"
def RandomString(len)
rand_max = RAND_CHARS.size
ret = ""
len.times{ ret << RAND_CHARS[rand(rand_max)] }
ret
end
end
end
Whats is my problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
application.rb
中启用模块加载You need to enable loading of modules in your
application.rb
您可以将其放入
config/initializers
中,它会自动加载,否则您将不得不使用混乱的require
从lib/
手动加载它>You could put this in
config/initializers
and it would get loaded automatically, otherwise you will have to manually load it fromlib/
using a messyrequire