Problem with validates in Rails 4

0

I have a situation that I can not understand what is wrong. I have a validation in the model that by the console it works correctly, but when running by the browser the form does the submit and ignores the validation.

My Model: class User < ActiveRecord :: Base

validates :name, presence: true

has_secure_password

end

I'm breaking my head.

    
asked by anonymous 15.11.2016 / 22:02

1 answer

0

I discovered my problem, in fact the form by the browser was validating only that when it gave error to save in my controller I was doing a "render: plain" to return the error message, so in this way the validates error did not was displayed. What I did was to change my controller to do the following in case of error rendering the form again.

def create        
    @user = User.new(user_params)
    if @user.save
        redirect_to @users
    else
        render '_form'
    end
end
    
15.11.2016 / 22:17