0
所以這可能會是一個非常愚蠢的問題,但我已經建立了Oauth作爲提供者與Ryan Bates的'Simple Omniauth Railscast類似的方式 - 我的問題是現在這是設置我應該在會話控制器中設置強大的參數,或者這不是必需的嗎?Omniauth和強大的參數
SessionsController.rb
class SessionsController < ApplicationController
def create
@user = User.find_by_uid(auth_hash[:uid]) || User.create_user(auth_hash)
session[:uid] = @user.id
if @user
redirect_to root_path
else
redirect_to root_path, flash: {signinerror: "Oops, something went wrong with your sign in. Please try again."}
end
end
def auth_hash
request.env['omniauth.auth']
end
def destroy
session[:uid] = nil
redirect_to root_path
end
end
User.rb
class User < ActiveRecord::Base
has_many :opinions
def self.create_user(auth_hash)
create do |user|
user.provider = auth_hash[:provider]
user.name = auth_hash[:info][:name]
user.uid = auth_hash[:uid]
user.username = auth_hash[:info][:nickname]
user.email = auth_hash[:info][:email]
user.image = auth_hash[:info][:image]
end
end
end
感謝