My home page calls this signup partial with this code
<div class="col-lg-6">
<%= render "users/signup" %>
</div>
This is the signup form code
<%= form_tag('/users', remote: true) do |f| %>
<div class="form-group">
<div class="row fm-space">
<div class="col-lg-6">
<%= text_field_tag :first_name, '', :name => "user[first_name]", :class => 'form-control', :placeholder => 'FIRST NAME' %>
</div>
<div class="col-lg-6">
<%= text_field_tag :last_name, '', :name => "user[last_name]", :class => 'form-control', :placeholder => 'LAST NAME' %>
</div>
</div>
</div>
<div class="form-group">
<div class="row fm-space">
<div class="col-lg-12">
<%= email_field_tag :email, '', :name => "user[email]", :class => 'form-control', :placeholder => 'EMAIL' %>
</div>
</div>
</div>
<div class="form-group">
<div class="row fm-space">
<div class="col-lg-12">
<%= password_field_tag :password, '', :name => "user[password]", :class => 'form-control', :placeholder => 'PASSWORD' %>
</div>
</div>
</div>
<div class="form-group">
<div class="row fm-space">
<div class="col-lg-12">
<%= password_field_tag :password_confirmation, '', :name => "user[password_confirmation]" , :class => 'form-control', :placeholder => 'PASSWORD CONFIRMATION' %>
</div>
</div>
</div>
<div class="checkbox">
<label>
<input type="checkbox"><span>I AGREE TO THE <a href="#">TERMS OF SERVICE</a></span>
</label>
</div>
<!-- Button trigger modal and submit form -->
<button type="submit" class="btn btn-primary btn-lg btn-block">SIGN UP</button>
<% end %>
My user_controller looks like this
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
session[:user_id] = @user.id
if request.xhr?
render partial: "questionnaire", object: @user, as: 'user'
else
# TODO: error handling if users created without AJAX form submission
redirect_to @user
end
else
# If @user is not valid, the new user form will be rendered with errors
render partial: "layouts/errors", object: @user, as: 'object'
end
end
def update
# TODO: the 2nd part of new user signup will effectively update our existing, basic user
@user = User.find_by(session[:user_id])
binding.pry
# flash[:notice] = "Thank you for signing up!"
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :company)
end
end
The partial error page that gets called when the form doesn’t validate correctly
<div class="row">
<% if object.errors.any? %>
<div class="alert alert-warning alert-dismissable col-md-6">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Form is invalid!</strong>
<ul>
<% object.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
Everything worked fine when the signup form wasn’t a partial and was on its on page. Only one error message would display. Now that the form is a partial on my home page i get three copy of the same error message.