Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

Renaud CUNY's Profile

GitHub User: rcuny

Comments by Renaud CUNY


Hi HuffModdy,
That's pretty much what I was trying to do :), thanks for putting me back on the way :).

For those who try the same, don't forget to add some logic to give back his session to the user if he cancels the signin or sinup for any reason (he returns to the homepage, for instance).

Something like this should do the trick (before_filter in application controller)

def fallbacks_to_guest
  if controller_name != 'registrations' && controller_name != 'sessions' && controller_name != 'passwords' && controller_name != 'confirmations'
    if current_user.nil? && session[:guest_user_id]
     user = User.find(session[:guest_user_id])
     sign_in_and_redirect(:user, user)

Thanks a lot Ryan for this great episode (one more :).

I'm just fighting a bit with Devise, and after a day sweating, I'm asking for help. First, here's the way I went, it could help some other folks around:
- I duplicated Devise Validatable class to apps/models/devise/models/validatable.rb, and patched the validation function to check for guest (password_required? and email_required? + created a custom one to ignore the validates_format_of :email as I store a uuid instead of an email for my guests, a bit dirty but efficient :)
- I then patched some of my controller on actions where I want to create a guest user on the fly (ex: if you create a content) and used sign_in_and_redirect(:user, my_new_gest_user) to log the guest in after creation.

The whole thing works fine, I start as anonymous, go to add a content, my patched controller does the job and I end-up as a guest user, logged in and with a content. I can then play with my app and create other pieces of content, works fine.

BUT (there is a but :) I'm stuck with the step where I need to create a new user if the guest wants to actually sign_up. Devise will refuse any sign_in or sign_up action, which makes sense as I'm kind of knocking on a door which is already opened :). Here I must admit I'm limited by my still-partial knowledge of Rails. I have the intuition I should override Devise controller to pass it as a parameter my, and tell him "Be nice, store this somewhere and let me signup" so I could then post-process it with something like your move_to method... but I can't find my way through Devise.

If anybody has gone through, I'll be glad to have a few crisps of advise to follow :).

Night here in Europe, I'll sleep on my code, cheers to those still working somewhere else :).


+1 on vickash explanation, the path you give seems pretty adapted to anyone who already has a running CarrierWave+Fog based app and wants to extend it to take benefit of CORS without too much refactoring.
Thanks a lot to both you and Ryan :).