Camilla

Joined

1,710 Experience
16 Lessons Completed
0 Questions Solved

Activity

Hello, Chris!

I have a rails appp, and I'm using Devise (without simple_form).
My registration form is in my homepage, root_path. I followed the tutorial from Devise and I'm able to register users in my landing page.

It works fine until the errors, that are shown at localhost:3000/users, it redirects me to a totally different page from the root_path.

So, what I would like is to show the errors below of each box just like they are when they're in the regular path like /registration/new.
Is that possible?

Hello.

I use 2 gems (gem 'devise' and gem 'omniauth-facebook').
The user is able both to sign_in ou sign_up with facebook. If a User did a regular sign up in the past, he's found by email, and if not he is created in the database.

My question now is how a User can update his account including password if he doesn't know the actual password because it's generated as a random number? I saw the Devise article https://github.com/heartcombo/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password but I also want users to update their passwords. Any thoughts?

MODEL:

class User < ApplicationRecord
def self.find_for_facebook_oauth(auth)
user_params = auth.slice("provider", "uid")
user_params.merge! auth.info.slice("email", "first_name", "last_name")
user_params[:facebook_picture_url] = auth.info.image
user_params = user_params.to_h

user = User.find_by(provider: auth.provider, uid: auth.uid)
user ||= User.find_by(email: auth.info.email) # User did a regular sign up in the past.
if user
  user.update(user_params)
else
  user = User.new(user_params)
  user.password = Devise.friendly_token[0, 20]  # Fake password for validation
  user.save(validate: false)
end

return user

end

CONTROLLER

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
user = User.find_for_facebook_oauth(request.env['omniauth.auth'])

if user.persisted?
  sign_in_and_redirect user, event: :authentication
  set_flash_message(:notice, :success, kind: 'Facebook') if is_navigational_format?
else
  session['devise.facebook_data'] = request.env['omniauth.auth']
  redirect_to new_user_registration_url
end

end

def failure
redirect_to root_path
end
end