Home > Ruby on Rails > Creating a record with your intended id

Creating a record with your intended id

In Rails, you can create a new record with the methods create; or new followed by save.  In both cases, the id of the record is automatically allocated.   This is how you can allocate your own id in a new record.  Why do we need that?  Well, I did, and someone probably need too.  For me, it’s a long story.  So I’ll just go into the How-to.

[Peep Code]

    s = Status.new(:name => ‘New’)
s.id=Status::NEW
s.save

[End of Peep Show]

Now you know why? 🙂

Categories: Ruby on Rails
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: