[Rails 3.2] validation on create not working

19 views
Skip to first unread message

Erwin

unread,
Dec 4, 2012, 5:03:28 AM12/4/12
to rubyonra...@googlegroups.com

class Place < ActiveRecord::Base

  validates :description, :presence => true
  validates :description, :uniqueness => {:case_sensitive => true, :on => :create }
  # also tried 
  # validates :description, :uniqueness => {:case_sensitive => true },  :on => :create

On update  ( in form fields, updated label,  same description )
params
{"event"=>{"place_attributes"=>{"label"=>"a very beautiful place", "description"=>"where you should go..."}}

@event.errors debugging
@messages={:"place.description"=>["has already been taken"]}>   !! uniqueness should not be checked ¿

thanks for any clue ..


Colin Law

unread,
Dec 4, 2012, 5:12:00 AM12/4/12
to rubyonra...@googlegroups.com
I don't understand what is happening that is not as you expect.
Please try and explain in more detail.

Colin

Erwin

unread,
Dec 4, 2012, 5:46:21 AM12/4/12
to rubyonra...@googlegroups.com, cla...@googlemail.com
 the[SOLVED]   I thought uniqueness of :description was checked on record update even with :on => :create condition for validate...   
it was , but my functional  test was not an update ...

I was using 
post :update, :locale => I18n.locale, :id => @event_0[:id]

it MUST be
put :update, :locale => I18n.locale, :id => @event_0[:id]
Reply all
Reply to author
Forward
0 new messages