In Rails I can do this to get the full error message (includes the name of the attribute)
book.errors.full_messages.each do |err|
puts err
end
My question is, how can I do the same thing but for a specific attribute?
I can't do this:
book.errors[:title].full_messages
As for now this is what I'm doing
book.errors[:title].each do |err|
puts " Title #{err}"
end
I'm looking forward if there's a better way
To get the full error message for a specific attribute use full_messages_for:
book.errors.full_messages_for(:title)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With