Reputation: 3638
I have a validation in my Author
model that checks if the current User
already is associated with an Author
record before creating a new Author
. While the validation is triggering, the error message isn't displaying in the form.
author.rb
belongs_to :user
validates :user, :uniqueness => {:message=>"An author account already exists for this user"}
author#new
<%= simple_form_for(@author) do |f| %>
<%= f.error_notification %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :bio %>
<%= f.button :submit %>
<% end %>
What happens is that it shows that there's an error, but no message appears. How can I fix this? Thank you!
Upvotes: 0
Views: 2034
Reputation: 26
simple_form only shows errors for input fields that have errors. You have an error on the attribute "user" but you have no input field for that where the error could be shown. You only have first name, last name and bio.
In your Controller you might want to redirect to the existing author instead when there already is an author. Or simply show @author.errors.full_messages to tell the end user what's going on.
Upvotes: 1