On 11/2/05, Thomas Balthazar
<thomas.tmp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello Railers,
>
> I can read in the Doc that the ''create'' method returns an
object,
> even if it fails to save the object into the DB :
>
> --
> create(attributes = nil)
> Creates an object, instantly saves it as a record (if the validation
> permits it), and returns it. If the save fail under validations, the
> unsaved object is still returned.
>
> --
>
> What I do is :
>
> def duplicate
> @content = Content.find(params[:id])
>
> @content.parent_id = @content.id
> @content.id = nil
> @content.status = ''b''
>
> render_text @content.create.to_s
> end
>
> and the render_text return ''false''.
> And my object is saved in the DB as expected.
>
> I don''t understand how it is possible, and I would like to know
how I
> can test if the ''save'' operation succeeded.
#create is a class method.
@content = Content.create :status => ''b''
@content.new_record? # if true, the model was not saved.
--
rick
http://techno-weenie.net