SageBeard / blockipedia

0 stars 1 forks source link

blockipedia/app/controllers/users/registrations_controller.rb #2

Closed SageBeard closed 7 years ago

SageBeard commented 7 years ago

I figured out how to route the registrations controller, however now I'm having an issue with the configure sign up param. I added the method below based on some stack overflow questions, but its not working for me. Could you point me in the right direction?

class Users::RegistrationsController < Devise::RegistrationsController
  before_action :configure_sign_up_params, only: [:create]
  before_action :configure_account_update_params, only: [:update]

  def configure_sign_up_params
     devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password) }
  end

  def new
    @user = User.new
  end

  def create

    @user = User.new
    @user.name = params[:user][:name]
    @user.email = params[:user][:email]
    @user.password = params[:user][:password]
    @user.password_confirmation = params[:user][:password_confirmation]

    if @user.save
      flash[:notice] = "Welcome to Blockipedia #{@user.name}!"
      create_session(@user)
      redirect_to root_path
    else
      flash.now[:alert] = "There was an error creating your account. Please try again."
      render :new
    end
  end

  def show
    @user = User.find(params[:id])
  end
end