ruby on rails - Redirect to Page after Facebook Sign Up -
i'm trying redirect user after successful facebook sign (not sign in).
i want redirect /getstarted/welcome
after user registers for first time.
my omniauth callback :
def facebook # need implement method below in model (e.g. app/models/user.rb) @user ||= user.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) if @user.persisted? # throw if @user not activated sign_in_and_redirect @user, event: :authentication if is_navigational_format? set_flash_message(:notice, :success, kind: "facebook") end else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end
for devise use
def after_sign_up_path_for(source) '/getstarted/welcome' end
my user model:
facebook settings
def self.find_for_facebook_oauth(auth, signed_in_resource = nil) user = user.where(provider: auth.provider, uid: auth.uid).first if user.present? user else user = user.create(first_name:auth.extra.raw_info.first_name, last_name:auth.extra.raw_info.last_name, facebook_link:auth.extra.raw_info.link, user_name:auth.extra.raw_info.name, provider:auth.provider, uid:auth.uid, email:auth.info.email, password:devise.friendly_token[0,20]) end end
can me set ?
i solved adding user model
attr_accessor `just_signed_up`
and setting in user.find_for_facebook_oauth
in part of block create new user (first_or_create
block).
edit: more explanation
so in ruby (not rails) there class method/macro called attr_accessor
(actually theres attr_reader
, attr_writer
, attr_accessor
shorthand calling other two)
if you, in user model write
class user attr_accessor :some_attribute
then you're able perform
u = user.first u.some_attribute = 'asdf' u.some_attribute # => 'asdf'
but attribute not going saved db, may used temporary storage of value in rails model.
another thing know there 2 "values" false in ruby, false
, nil
.
using 2 tricks may create new user , temporarily set flag on object
u = user.create u.just_signed_up = true u.just_signed_up # => true u.reload! # fetches record db u.just_signed_up # => nil
and since nil false, check fail every user except ones created!
Comments
Post a Comment