このRailscastに従ってomniauth-identityを実装しました。
だから私はこのようなものになりました:
ID.rb:
class Identity < OmniAuth::Identity::Models::ActiveRecord
attr_accessible :name, :email, :password, :password_confirmation
validates_presence_of :name
validates_uniqueness_of :email
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
end
ユーザー.rb:
class User < ActiveRecord::Base
def self.from_omniauth(auth)
find_by_provider_and_uid(auth["provider"], auth["uid"]) || create_with_omniauth(auth)
end
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
user.email = auth["info"]["email"]
end
end
スキーマ.rb:
create_table "identities", :force => true do |t|
t.string "name"
t.string "email"
t.string "password_digest"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "admin", :default => false
t.string "uid"
t.string "provider"
t.string "name"
t.string "email"
end
パスワードはモデルによって処理されているため、 FactoryGirlでユーザーを作成する方法がよくわかりません。Identity
パスワードを省略すればユーザーを作成できますが、パスワードがないとサインインできません。
これを機能させる方法が本当にわかりません。これに対する一般的な解決策はありますか?