1
不太確定這裏發生了什麼,因爲Devise 是直到最近才工作。Rails:設計返回「Invalid Strategy ...」
簡而言之,我已將Devise配置爲可與Omniauth配合使用。當我嘗試運行本地服務器時,出現了一些問題。
終端提出了警告:
You provided devise_for :users but there is no model User defined in your application
當我嘗試實際訪問該網站在瀏覽器中,我得到:
Invalid strategy rememberable
我檢查了我的用戶模型,設計初始,和路線,都似乎退房。我還驗證了這些表存在於我的數據庫中,並且可以訪問。下面是單個文件:
User.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :twitter_oauth, :oauthable
attr_accessible :email, :password, :password_confirmation, :remember_me
def apply_omniauth(omniauth)
case omniauth['provider']
when 'facebook'
self.apply_facebook(omniauth)
when 'open_id'
self.email = omniauth['user_info']['email'] if email.blank?
end
authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'], :token =>(omniauth['credentials']['token'] rescue nil))
end
def facebook
@fb_user ||= FbGraph::User.me(self.authentications.find_by_provider('facebook').token)
end
def password_required?
(authentications.empty? || !password.blank?) && super
end
protected
def apply_facebook(omniauth)
if (extra = omniauth['extra']['user_hash'] rescue false)
self.email = (extra['email'] rescue '')
end
end
end
設計初始化
Devise.setup do |config|
config.mailer_sender = "please[email protected]"
require 'devise/orm/active_record'
config.stretches = 10
config.pepper = "..."
end
的routes.rb
Project::Application.routes.draw do
match '/auth/:provider/callback' => 'authentications#create'
devise_for :users, :controllers => {:registrations => 'registrations'}
resources :authentications
end
就是這樣,實際上。看起來我從我以前使用的授權方法中得到了一些剩餘的行李。 – 2011-02-08 02:01:20