I have included validation for my sign up page, but when I load the sign-up page Error appears. It should show errors after clicking submit button What i need to do?
My sign-up page
<% if !flash[:notice].blank? %> <div class="notice"> <%= flash[:notice] %> </div> <% end %> <%= form_for @user,validate: true do |f| %> <% if [email protected]? %> <% if @user.errors.any? %> <ul class="Signup_Errors"> <% for message_error in @user.errors.full_messages %> <li>* <%= message_error %></li> <% end %> </ul> <% end %> <% end %> <%= f.label("Name:") %> <%= f.text_field(:user_name, class: "form-control") %></br> <%= f.label("Email Address:") %> <%= f.text_field(:email_id, class: "form-control") %></br> <%= f.label("Password:") %> <%= f.password_field(:password, class: "form-control") %></br> <%= f.label("Confirm Password:") %> <%= f.password_field(:password_confirmation, class: "form-control") %></br> <%= f.submit("Register",class: "btn btn-primary") %> <a class="btn btn-primary" style="margin-left:20px" href="/login" >Login</a> <% end %> My model where I have included my validations
User.rb
class User < ApplicationRecord has_many :reviews has_secure_password EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i validates :user_name, :presence => true, :on => :create, :uniqueness => true, :length => { :in => 3..20 } validates :email_id, :presence => true, :on => :create, :uniqueness => true, :format => EMAIL_REGEX validates :password, :presence => true, :on => :create, :confirmation => true #password_confirmation attr validates :password_confirmation, :presence => true end Controller
def new puts "****Inside New Method******" @user = User.new end def create puts "****Inside create Method******" @user = User.new(user_params) puts @user.user_name if @user.save puts "** USER DETAILS SAVED SUCCESSFULLY****" flash[:notice] = "Registration successful, please login" flash[:color] = "valid"; redirect_to "/login" else flash[:notice] = "Invalid Form" flash[:color] = "invalid" end end When I load the page, Error appears before clicking the submit button I have included :on => :create but it doesn't work
please help!!