I prepared a form for adding records to the table. I want the model
class to validate the uniqeuness of the name field but it doesn’t give
any errors for the duplicate record.
Here is the controller :
class PetController < ApplicationController
def new
check_authentication
if request.post?
begin
@file = params[:pet_image]
if @file.original_filename.length > 0
pet = Pet.new
#set the fields
pet.save
File.open(filename, “wb”) { |f| f.write(@file.read) }
redirect_to(:controller=>‘user’, :action=>‘petadmin’)
end
end
end
end
def show
check_authentication
end
end
Here is the model :
class Pet < ActiveRecord::Base
belongs_to :user
validates_presence_of :name,:pet_image
validates_uniqueness_of :name, :on => :save, :message => “is already
used.”
end
so, why doesn’t “validates_uniqueness_of” helper work ?