我按照這個教程中色器件安裝omniauth + mongoid:NoMethodError在AuthenticationsController#創建未定義的方法`RandomString」絃樂:
https://github.com/fertapric/rails3-mongoid-devise-omniauth/wiki/OmniAuth-Installation-Tutorial
我設計1.4.5 + omniauth 0.3.0 +導軌3.1.0。
我在devise.rb下一個信息:
config.omniauth :facebook, 'My_CONSUMER_KEY', 'MY_CONSUMER_SECRET', :scope => 'user_hometown, user_about_me, email'
在本教程中,這樣的配置已經是創建一個初始化/ 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
請告訴我是我的問題
作爲一個說明,在Ruby的方法名不應該大寫字母加載它。常量是'ALL_CAPS',類是'CapsFirst',方法應該是'lower_case'。 – tadman
謝謝!爲你的筆記! – hyperrjas