Problem with validates in Rails 4

Asked

Viewed 49 times

0

I have a situation I can’t understand what’s wrong. I have a validation in the model that the console works correctly, but when running through the browser the form does Submit and ignores the validation.

My Model: class User < Activerecord::Base

validates :name, presence: true

has_secure_password

end

I’m racking my brain.

  • Have to display the params?

1 answer

0

I discovered my problem, actually 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 this way the validates error was not displayed. What I did was change my controller to do the following in case of error renders the form again.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.