Forum: Ruby on Rails [Rails 3.2] validation on create not working

Posted by Kad Kerforn (kadoudal)
on 2012-12-04 11:04
(Received via mailing list)
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 ..
Posted by Colin Law (Guest)
on 2012-12-04 11:13
(Received via mailing list)
On 4 December 2012 10:03, Erwin <yves_dufour@mac.com> wrote:
> 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

I don't understand what is happening that is not as you expect.
Please try and explain in more detail.

Colin
Posted by Kad Kerforn (kadoudal)
on 2012-12-04 11:48
(Received via mailing list)
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]


Le mardi 4 dcembre 2012 11:12:00 UTC+1, Colin Law a crit :
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.