以下のサイト参考にomniauth-facebookを導入してみた。
OmniAuthで認証機能を作る
開発環境では平気だったんだけど、Herokuにあげたらエラって、
log見てみたら以下のエラーがあった。
NoMethodError (undefined method `find_by_provider_and_uid' for #<Class:0x007fcb2884a328>):
find_by_provider_and_uidが定義されてないと。
session_controller.rb
に書いてある。
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_path
end
以下のサイトにfind_by
にハッシュ渡して使えって書いてた。
What's New in Rails 4
下のように書きなおしたら使えるようになった。
def create
auth = request.env["omniauth.auth"]
user = User.find_by(provider: auth["provider"], uid: auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_path
end
解決!