I am using this gem: https://github.com/bootstrap-ruby/rails-bootstrap-forms. The gem is supposed to highlight the input box in red if a validation is not met. I have a couple issues. First, the inline validation errors are not working. Secondly, and more importantly, my model validation errors are not working at all.
How do I change the validations to make sure they work? Is there something special I need to do to make the gem work on the front end? Or would it be best to use another method for front end validation errors?
Thank you so much!
edit.html.erb
<!-- Change Password Modal -->
<div id="changepasswordmodal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3 class="">Change Your Password</h3>
</div>
<div class="modal-body">
<%= bootstrap_form_for @user, url: change_password_path, label_errors: true do |p| %>
<%= p.password_field :current_password, label: "Old Password", placeholder: "Old Password", class: "input-lg required" %>
<%= p.password_field :password, label: "New Password", placeholder: "New Password", class: "input-lg required" %>
<%= p.password_field :password_confirmation, label: "Confirm New Password", placeholder: "Confirm New Password", class: "input-lg required"%>
<%= p.submit "Change Password", :class=> "btn btn-primary" %>
<% end %>
</div>
</div>
</div>
</div>
users_controller.rb
def change_password
@user = User.find(@current_user)
current_password = params[:user][:current_password]
user = User.authenticate(@user.email, current_password)
if @user && user
User.update(@user, change_password_params)
@user.save
flash[:success] = "Password successfully changed!"
redirect_to edit_user_path(@current_user)
else
flash[:danger] = "Your old password was incorrect. Please try again."
redirect_to edit_user_path(@current_user)
end
end
private
def change_password_params
params.require(:user).permit(:password, :password_confirmation)
end
user.rb
validates :password, :presence =>true, :confirmation =>true
validates_confirmation_of :password