1

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
user4889724
  • 121
  • 1
  • 12
  • This is how the documentation shows form_for: (@user, label_errors: true, inline_errors: true). Have you tried surrounding it with parenthesis like in the docs? – vanburen Sep 30 '15 at 22:50
  • Yes, I have tried that. Still cant get the form to confirm password – user4889724 Sep 30 '15 at 22:57
  • I see now that if the password and password confirmation inputs are different, the form sends the server side error (which happens to be that the old password was incorrect). So the validations are working somewhat, but the client side bootstrap form validations cannot be seen – user4889724 Sep 30 '15 at 23:22

0 Answers0