subsriber.rb
class Subscriber < ActiveRecord::Base
validates_confirmation_of :email, :message => "Your emails don't match!"
end
I have this in my rails app. When I create a new record without matching email
Here’s my create action:
def create
@subscriber = Subscriber.new(params[:subscriber])
if @subscriber.save
redirect_to root_path, :notice => "You've been subscribed!"
else
render 'new'
end
end
How do I make the error message show up in the view file? I don’t see anything in the docs saying I need to add something to my views but the message is not showing up.
You actually do need to add something to your view to show the message.
Rails normally does this for you when you create a scaffold, but if you need to do it manually for a field, you need to add something like this to your HTML template: