mercredi 2 septembre 2020

Find User from the params we get

im a not a rails expert but i want to know that how can I find the User by its email as I'm getting before in params . & in else section I want to create new user by using that parameters

  def google
    user = User.find_by email: user[:email]
    if user
      user.generate_new_authetication_token
      json_response "User Information & already exist" , true, {user: user}, :ok
    else
          ??????????
    end
    if user.save
      json_response "Signed up Successfully ", true, {user: user}, :ok
    else
      json_response "something wrong ", false, {}, :unprocessable_entity
    end
  end

And another private function from which I'm getting user params

private

  def google_params
    params.require(:user).permit(:uid , :email )
  end

Aucun commentaire:

Enregistrer un commentaire