> just an advice for other participants:
   validates_presence_of :address, ..., :if  => :address?

this is like a guard verifying that people wear a badge... but only if they
have a badge

Raul

On Sat, Nov 8, 2008 at 10:53 AM, Aleš Bednařík <[EMAIL PROTECTED]>wrote:

>
> Many thanks. I understand it now much better.
>
> Just an advice for other participants. I have used the :if directive in the
> ActiveRecord validation definition for the :address not to validate
> existence of this property when the object is created in the first form.
>
> Ales
>
> class User < ActiveRecord::Base
>    validates_presence_of :name, :age, :hobby,
>      :on => :create,
>      :message => "cannot be blank."
>    validates_presence_of :address,
>      :on => :update,
>      :message => "cannot be blank.",
>      :if => :address?
> end
>
> > ------------ Původní zpráva ------------
> > Od: raul parolari <[EMAIL PROTECTED]>
> > Předmět: Re: [rails-development] Re: 5526 - Action Controller Basics -
> Homework
> > Datum: 02.11.2008 16:57:59
> > ----------------------------------------
> > > validation is called only when an object is persisted to the relational
> > DB, never with object creation / modification in memory.
> >
> > u=User.new(:name => '', ....)
> > u.valid?
> > u.errors.on :name
> >
> > Validation is run, although there was no attempt to save to db.
> >
> > This is key to solve the exercise (in a graceful way)
> >
> > Raul
> >
> > 2008/11/2 Aleš Bednařík <[EMAIL PROTECTED]>
> >
> > >
> > > Hi Petro and Raul,
> > >
> > > it was interesting for me to follow your conversation. I just want to
> be
> > > sure if I understand the ActiveRecord validation correctly and need a
> > > confirmation of the following:
> > >
> > > Validation is called only when an object is persisted to the relational
> DB,
> > > never with object creation / modification in memory.
> > > The :on parameter can have following three values:
> > > :on => :create - is called only for persistence of a NEW object -
> creation
> > > (memory -> database)
> > > :on => :update - is called only for persistence of already earlier
> > > persisted object - modification
> > > :on => :save - is called in both situation described above
> > >
> > > Is that correct?
> > >
> > > By the way, my first approach was to store name, age and hobby
> separately
> > > to the session. The idea with the object creation (in memory) and
> storing
> > > the whole object seems to me very elegant.
> > >
> > > Ales
> > >
> > > > ------------ Původní zpráva ------------
> > > > Od: raul parolari <[EMAIL PROTECTED]>
> > > > Předmět: [rails-development] Re: 5526 - Action Controller Basics -
> > > Homework
> > > > Datum: 29.10.2008 15:45:46
> > > > ----------------------------------------
> > > > Hi, Pietro,
> > > >
> > > > > now I'm a better rails citizen ;-)
> > > >
> > > > Me too; I had no idea that we could do an "intermediate validation"
> (and
> > > > without creating the object) using ActiveRecord. It was just a few
> emails
> > > > back that I was trying to cast your interpretation of the
> requirements as
> > > "*ad
> > > > litteram*" (Lol!). Ad litteram my foot; you were just right.
> > > >
> > > > > If you happen to travel here in northern Italy...
> > > >
> > > > Thank you so much. I was born there (a bit up north from you, Tione
> di
> > > > Trento); wine (not to mention food) is fantastic.
> > > > As for the beer, one is waiting for me in Szczecin (Poland), from
> Pawell,
> > > so
> > > > I will be fine..:-).
> > > >
> > > > To more intelligent discussions (and fluids.. :-)
> > > >
> > > > Raul
> > > >
> > > >
> > > > On Wed, Oct 29, 2008 at 1:23 AM, Pietro Maggi <[EMAIL PROTECTED]
> >
> > > wrote:
> > > >
> > > > > On Wed, Oct 29, 2008 at 8:09 AM, raul parolari <
> [EMAIL PROTECTED]
> > > >
> > > > > wrote:
> > > > > >
> > > > > >   yes, this is an interesting misunderstanding. When we study
> Ruby,
> > > we
> > > > > may
> > > > > > have a class Player, and when we do:
> > > > > >
> > > > > >    lionel = Player.new(:name => "messi", :team => "barcelona",
> ...)
> > > > > >
> > > > > > we say that we have created an object of the class Player.
> > > > > >
> > > > > > But it is different in ActiveRecord (AR); the word creation means
> > > > > "creating
> > > > > > in the database". AR does not care about much about our
> u=User.new();
> > > but
> > > > > it
> > > > > > cares when we save that user u! that is the moment of the
> > > "creation"...
> > > > > >
> > > > > [SNIP]
> > > > >
> > > > > Yep, I initially mixed them up. After a bit of reading I finally
> got
> > > > > it and now I'm a better rails citizen ;-)
> > > > >
> > > > > Thanks again Raul
> > > > > If you happen to travel here in norther Italy* I'll happily offer
> you
> > > > > some tasty wine (the usual way of say how much someone appreciate
> your
> > > > > help, it's to offer a beer but, hey, I'm Italian ;-).
> > > > >
> > > > > Pietro
> > > > >
> > > > >
> > > > > * I'm here:
> > > > >
> > > >
> > >
> >
> http://maps.google.com/maps?f=q&hl=en&geocode=&q=lecco,+italy&sll=37.0625,-95.677068&sspn=49.310476,79.101563&ie=UTF8&g=lecco,+italy&t=h&ll=45.896699,9.30542&spn=0.682404,1.235962&z=10&iwloc=addr
> > > > >
> > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> > > > >
> > >
> >
> >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to