2011-10-04 56 views
1

我按照這個教程中色器件安裝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 

請告訴我是我的問題

+0

作爲一個說明,在Ruby的方法名不應該大寫字母加載它。常量是'ALL_CAPS',類是'CapsFirst',方法應該是'lower_case'。 – tadman

+0

謝謝!爲你的筆記! – hyperrjas

回答

1

您需要啓用加載您的模塊application.rb

+0

謝謝你,我在配置啓用/ aplication.rb這樣的: config.autoload_paths + =%W(#{} config.root /演員) 需要 'string_extensions' 包括StringExtensions 但現在我趕上下一個錯誤在我的網頁(是錯誤網頁渲染): 網址是: 的http://本地主機:3000/sign_up#_ = _ 而在紅色警報在註冊表單: Auhtentication失敗! ! – hyperrjas

0

你可以把這個config/initializers,它會得到自動加載,否則你將不得不手動從lib/使用凌亂require

+0

謝謝您的回覆,現在問題是我發現錯誤:Auhtentication失敗!我不知道爲什麼現在在紅色的窗體中顯示這個錯誤 – hyperrjas

+0

聽起來像一個不同的問題。 – tadman

相關問題