Redirect to Page after Facebook Sign Up

天涯浪子 提交于 2019-12-04 17:41:25

I solved it by adding to my User model

attr_accessor `just_signed_up`

and setting it in User.find_for_facebook_oauth in this part of the block where I create a new user (first_or_create block).

EDIT: more explanation

So in Ruby (not Rails) there is a class method/macro called attr_accessor (actually theres also attr_reader and attr_writer, attr_accessor is a shorthand for calling the other two)

If you, in your User model write

class User
  attr_accessor :some_attribute

then you're able to perform

u = User.first
u.some_attribute = 'asdf'
u.some_attribute # => 'asdf'

but this attribute is not going to be saved to DB, so it may be used as a temporary storage of some value in Rails model.

Another thing to know is that there are only two "values" that are false in Ruby, those are false and nil.

Using those two tricks you may create a new user and temporarily set this flag on the object

u = User.create u.just_signed_up = true u.just_signed_up # => true u.reload! # fetches record from DB u.just_signed_up # => nil

and since nil is false, this check will fail for every user except for ones you just created!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!