Forum: Ruby on Rails Help concatenating letters and numbers

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ed3050ec0a96c03ef1304e7ad1ff46fb?d=identicon&s=25 The Neurochild (Guest)
on 2008-11-12 00:22
(Received via mailing list)

I need to do the following in rails:

I have a string with the following composition: AAA-BBB-2008-000001

The first to groups are strings, named @string1 and @string2. The
third is the year, (reflected using"%Y")) and the
last part is an integer, @integer1.

I'm using a PostgreSQL 8 database and I need to put that composition
on a string.I have no problem with the string variables and the year.
The catch here is the integer, it increases everytime I do a new
registry and, when a new year comes, it resets to 1. More over, I need
the integer to be 6-digit.I don't know how to do that, but I know the
logic of th increments:

When the integer is 10, I need it to be 000010; when it's 100, 000100;
1000 => 001000 and so on.

And let's suppose one of our string changes, for example. It also must
resets the integer to 1.

As you can see, it's a unique composition.

As the id from the database keeps increasing, that number won't work
on me. I need to set it apart, without using that number. And that
count must be kept, whenever I log in to my app.

Is it hard to do this stuff?


The Neurochild
D69d23d8e811e8ab2a8593380d6ede63?d=identicon&s=25 Jeff Emminger (jemminger)
on 2008-11-12 15:02
(Received via mailing list)
you can use sprintf formatting for the integer:

 @integer1 = 10
 int_formatted = "%06d" % @integer1 # returns "000010"

I don't understand the other requirements enough to help further
This topic is locked and can not be replied to.