Rahul
Rahul

Reputation: 47146

Giving UUID(string) as default id for tables

Rails gives values of table ids as integers. It starts from 1 and keeps increasing. How can I modify this default behavior? How can I make rails to generate a random string and pass it on as id for the tables?

Upvotes: 3

Views: 404

Answers (1)

allesklar
allesklar

Reputation: 9600

It is strongly recommended you do NOT modify this behavior.

The whole point of using Rails is to use a whole lot of programming magic and goodies provided by the framework. These advantages will come on account of following all conventions Rails impose upon you.

Every time you wish to go a different route such as changing the nature of the table ids you should stop and think of a different solution to whatever problem you may have.

Learning Rails programming is about learning many of its conventions and aligning your programming style to them. For most of us this will have the added benefit of teaching us better coding techniques and upping our level.

Good luck to you.

Upvotes: 0

Related Questions