Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when registering new users #175

Closed
keilmillerjr opened this issue Oct 22, 2023 · 3 comments
Closed

Error when registering new users #175

keilmillerjr opened this issue Oct 22, 2023 · 3 comments

Comments

@keilmillerjr
Copy link

source "https://rubygems.org"
passwordless (1.0.0)
rails (7.1.1)

I could use help. I am not sure if I am doing something wrong, or this is a bug. User is created, but I get an error when trying to sign them in automatically. See documentation Registering new users. Thank you in advance.

ActiveRecord::ActiveRecordError in UsersController#create
Cannot touch on a new or destroyed record object. Consider using persisted?, new_record?, or destroyed? before touching.

Extracted source (around line #19):
17
18  if @user.save
19    sign_in(build_passwordless_session @user)
20    redirect_to root_path, success: 'Welcome aboard!'
21  else
22    flash[:error] = @user.errors.full_messages
class UsersController < ApplicationController
invisible_captcha only: [:create], honeypot: :last_name

  def index
    @users = User.all
  end

  def new
    @user = User.new
  end

  def edit
  end

  def create
    @user = User.new user_params

    if @user.save
      sign_in(build_passwordless_session @user)
      redirect_to root_path, success: 'Welcome aboard!'
    else
      flash[:error] = @user.errors.full_messages
      render :new
    end
  end

  private

  def user_params
    params.require(:user).permit(:email, :name)
  end
end

@mikker
Copy link
Owner

mikker commented Oct 31, 2023

Hi! Try using the create_passwordless_session helper instead? This may be an error in the docs

@mikker
Copy link
Owner

mikker commented Nov 7, 2023

Updated the README

@mikker mikker closed this as completed Nov 7, 2023
@keilmillerjr
Copy link
Author

Updated the README

a7891a8

All is well with the cosmos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants