Well so its of no use if one wants to check if the record is a brand
new record or an updated one

On Jul 1, 6:13 pm, RailsFan Radha <[email protected]> wrote:
> I just read this from the "Simply Rails 2" book
>
> model.new_record?
> If it is not yet saved, will return true.
> If saved, will return false.
>
> Excerpt from this book:
>
> From the Rails console, let’s create this Story class, and an instance
> of the class called story, by entering these commands:>> class Story < 
> ActiveRecord::Base; end
> => nil
> >> story = Story.new
>
> => #<Story id: nil, name: nil, url: nil, created_at: nil,
> updated_at: nil>>> story.class
>
> => Story(id: integer, name: string, link: string,
> created_at: datetime, updated_at: datetime)
> As you can see, the syntax for creating a new ActiveRecord object is
> identical to the syntax we used to create other Ruby objects in Chapter
> 3. At this point, we’ve created a new Story object. However, this object
> exists in memory only—we haven’t stored it in our database yet.
> We can confirm the fact that our Story object hasn’t been saved yet by
> checking the return value of the new_record? method:
>
> >> story.new_record?
>
> => true
> Since the object has not been saved yet, it will be lost when we exit
> the Rails console. To save it to the database, we need to invoke the
> object’s save method:>> story.save
>
> => true
> Now that we’ve saved our object (a return value of true indicates that
> the save method was successful) our story is no longer a new record.
> It’s even been assigned a unique ID, as shown below:>> story.new_record?
> => false
> >> story.id
>
> => 1
>
>
>
> Filipe Quadros Borges wrote:
> > try '[email protected]_record'
>
> >http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001843
>
> > On Thu, Jul 1, 2010 at 9:57 PM, badnaam <[email protected]> wrote:
> >> To unsubscribe from this group, send email to 
> >> [email protected].
> >> For more options, visit this group 
> >> athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > Filipe Quadros Borges
>
> > email: [email protected]
> > msn: [email protected]
>
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to