0

I'm using strong parameters in my User controller in my Rails 4 application.

def new
    @user = User.new
end

def create
    @user = User.new(user_params)
    if !@user.save
        render :new
    end
end    

private

def user_params
    params.require(:user).permit(:first_name, :last_name, :address_1, :address_2, :city, :state, :zip, :phone, :email, :password, :ssn)
end

I also have validation in the User model.

    validates_presence_of :first_name, :last_name

If the user fills out my form to create their account and don't pass the validation, when the controller renders the new action, none of the previously fields the user filled out are populated, the entire form is blank. Am I missing something?

jmcharnes
  • 707
  • 12
  • 23

2 Answers2

0

It seems you made new instance variable when validation fails.

You have to use failed instance variable in new form.

if you can't understand my answer please add your code of create action and form view.

Chen
  • 578
  • 2
  • 9
0

I was using Single Table Inheritance and was pre-designating the type of user it would be. Once I removed STI, my fields were appearing in the form no problem.

jmcharnes
  • 707
  • 12
  • 23