# How write input form (layout/controller) so I can enter Id

**URL:** <https://www.ruby-forum.com/t/how-write-input-form-layout-controller-so-i-can-enter-id/78755>\
**Category:** Rails\
**Created:** [December 28, 2005, 11:46am UTC](https://www.ruby-forum.com/t/how-write-input-form-layout-controller-so-i-can-enter-id/78755 "2005-12-28T11:46:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![radek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@radek](https://www.ruby-forum.com/u/radek)\
**Post date:** [December 28, 2005, 11:46am UTC](https://www.ruby-forum.com/t/how-write-input-form-layout-controller-so-i-can-enter-id/78755/1 "2005-12-28T11:46:10Z")

</div>

I reformulate my needs. How I can write (layout/controller) so I can  
read value of Id from the new form when creating new record.

With following structure:  
CREATE TABLE words (  
id INTEGER PRIMARY KEY,  
word VARCHAR(40)  
);

I want enter new records like:  
id=47812, word=‘pes’  
id=1382, word=‘krough’  
id=67145, word=‘brum’

– Radek

---

<div class="post-metadata">

**Author:** ![radek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@radek](https://www.ruby-forum.com/u/radek)\
**Post date:** [December 28, 2005, 8:19pm UTC](https://www.ruby-forum.com/t/how-write-input-form-layout-controller-so-i-can-enter-id/78755/2 "2005-12-28T20:19:51Z")

</div>

Radek Hnilica wrote:

> id=47812, word=‘pes’  
> id=1382, word=‘krough’  
> id=67145, word=‘brum’
> 
> – Radek

This obviously doesn’t exactly answer your question, but I would think  
you would want a table like this

id integer auto\_increment primary key  
id\_value integer not null (name it whatever you want, it corresponds to  
the user-specified id value in your table  
word varchar(40)

The id column is rails is meant to be an auto-increment value with no  
meaning within your problem space.

What benefits do you feel your scheme has over this one?

---

<div class="post-metadata">

**Author:** ![radek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@radek](https://www.ruby-forum.com/u/radek)\
**Post date:** [December 28, 2005, 10:14pm UTC](https://www.ruby-forum.com/t/how-write-input-form-layout-controller-so-i-can-enter-id/78755/3 "2005-12-28T22:14:39Z")

</div>

On Wed, Dec 28, 2005 at 02:18:03PM -0500, Mike H. wrote:

> Radek Hnilica wrote:
> 
> This obviously doesn’t exactly answer your question, but I would think  
> you would want a table like this
> 
> id integer auto\_increment primary key  
> id\_value integer not null (name it whatever you want, it corresponds to  
> the user-specified id value in your table  
> word varchar(40)

I do not underestand what you mean. Your model doesnt fit the  
constraints. Did you mean something like I’m experimenting now with:

CREATE TABLE employees (  
id SERIAL PRIMARY KEY,  
pin INTEGER UNIQUE, – worker personal identification  
first\_name VARCHAR(30) NOT NULL,  
last\_name VARCHAR(30) NOT NULL  
);

Where the pin is unique identification which is assigned to each  
employee and newer change. It has nothing to do with ATM or  
passwords. It’s the same if the employee leave our firma and later  
get on. His name can change, but his pin not.

> The id column is rails is meant to be an auto-increment value with no  
> meaning within your problem space.
> 
> What benefits do you feel your scheme has over this one?

I’m not sure, there are many unresolved things yet. For instance:

1. Which fields (columns) can be in relations has\_many, belongs\_to.  
What restrictions I can place on database model to not bother the  
rails. What I mean. In the related table, say  
CREATE TABLE some\_record\_headers (  
id SERIAL PRIMARY KEY,  
worker\_id INTEGER NOT NULL REFERENCES employees(pin),  
relay\_number INTEGER NOT NULL,  
…  
);  
In such table what field I have te REFERENCE, the natural key or the  
synthetic key.

2. How do other people underestand the data model. The people  
accessing the database through another tools, completly unrelated to  
Rails or Ruby. In mine example, another worker will connect to  
database to read some\_record\_headers and some\_record\_items. He is  
completly uninterested in workers name or some synthetic id, but he  
need to know the workers pin.

3. What about some task and processes I need to implement as a  
standalone programs, processing the database and do its own things.

Sometimes it can be only one or few tables in which in need to use my  
own natural key instead of synthetic. In many cases I can live with  
numeric keys and the records need only be created. The key will never  
changes.

# – Radek Hnilica [http://www.hnilica.cz](http://www.hnilica.cz)

No matter how far down the wrong road you’ve gone, turn back.  
Turkish proverb  
… so turn back … Now!
