# How to create a LOV \[ List of Values in a Rails Application

**URL:** <https://www.ruby-forum.com/t/how-to-create-a-lov-list-of-values-in-a-rails-application/86345>\
**Category:** Rails\
**Created:** [February 21, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/how-to-create-a-lov-list-of-values-in-a-rails-application/86345 "2007-02-21T17:04:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinooz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dinooz](https://www.ruby-forum.com/u/Dinooz)\
**Post date:** [February 21, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/how-to-create-a-lov-list-of-values-in-a-rails-application/86345/1 "2007-02-21T17:04:59Z")

</div>

I have 3 tables for a Sarbanes Oxley application. Servers , Databases  
and Applications.

another set of tables for the Model: Servers\_Databases,  
Databases\_Applications and Servers\_Applications.

My question here is how can setup a LOV in order to let the join  
tables have a LOV from the Servers, Databases or Applications.

How would the model be applied in has\_many … :trough …

This is really cool but a little bit confusing.

Thanks in advance for your help…

##### 

./script/generate scaffold\_resource Server name:string cat:string  
net\_face:integer ids:integer mon\_man:integer mon\_aut:integer  
int\_ip:string ext\_ip:string desc:string bu\_media:string  
bu\_method:string bu\_data\_freq:string os\_vendor:string os:string  
os\_version:string

./script/generate scaffold\_resource App name:string fsa:integer  
fsa\_logic:string description:string bu\_data:string

./script/generate scaffold\_resource Db name:string cat:string  
description:string mon\_man:integer mon\_auto:integer

./script/generate scaffold\_resource App\_svr server\_id:integer  
app\_id:integer

./script/generate scaffold\_resource Db\_app db\_id:integer  
app\_id:integer

./script/generate scaffold\_resource Db\_svr db\_id:integer  
server\_id:integer

rake db:migrate

##### 

In a restful way I have the URL’s working properly for:

[http://127.0.0.1:3000/dbs/](http://127.0.0.1:3000/dbs/)  
[http://127.0.0.1:3000/apps/](http://127.0.0.1:3000/apps/)  
[http://127.0.0.1:3000/servers/](http://127.0.0.1:3000/servers/)

[http://127.0.0.1:3000/db\_apps/](http://127.0.0.1:3000/db_apps/)  
[http://127.0.0.1:3000/db\_svrs/](http://127.0.0.1:3000/db_svrs/)  
[http://127.0.0.1:3000/app\_svrs/](http://127.0.0.1:3000/app_svrs/)

Now my question is how to create a LOV in order to build my  
application for the Join tables in DB\_APPS like to have the option to  
show the LOV based on the Databases, Applications or Servers table and  
not the ID. Also in the Form like to be able to select from the other  
table.

For the Model how would exactly work the … has\_many :trough …

Thanks in advance for your help.

Dino.

---

<div class="post-metadata">

**Author:** ![Dinooz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dinooz](https://www.ruby-forum.com/u/Dinooz)\
**Post date:** [February 21, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/how-to-create-a-lov-list-of-values-in-a-rails-application/86345/2 "2007-02-21T18:40:21Z")

</div>

Thank you Mike for your reply here is layout of the current tables:  
3 Main tables: servers , dbs , apps [ For some reason  
scaffold\_resource did not like the work database/s application/s]

These 3 tables work together with the tables: app\_svrs, db\_apps and  
db\_svrs

DROP TABLE IF EXISTS `prs_sarbox_development`.`servers`;  
CREATE TABLE `prs_sarbox_development`.`servers` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`cat` varchar(255) default NULL,  
`net_face` int(11) default NULL,  
`ids` int(11) default NULL,  
`mon_man` int(11) default NULL,  
`mon_aut` int(11) default NULL,  
`int_ip` varchar(255) default NULL,  
`ext_ip` varchar(255) default NULL,  
`desc` varchar(255) default NULL,  
`bu_media` varchar(255) default NULL,  
`bu_method` varchar(255) default NULL,  
`bu_data_freq` varchar(255) default NULL,  
`os_vendor` varchar(255) default NULL,  
`os` varchar(255) default NULL,  
`os_version` varchar(255) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`dbs`;  
CREATE TABLE `prs_sarbox_development`.`dbs` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`cat` varchar(255) default NULL,  
`description` varchar(255) default NULL,  
`mon_man` int(11) default NULL,  
`mon_auto` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`apps`;  
CREATE TABLE `prs_sarbox_development`.`apps` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`fsa` int(11) default NULL,  
`fsa_logic` varchar(255) default NULL,  
`description` varchar(255) default NULL,  
`bu_data` varchar(255) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`app_svrs`;  
CREATE TABLE `prs_sarbox_development`.`app_svrs` (  
`id` int(11) NOT NULL auto\_increment,  
`server_id` int(11) default NULL,  
`app_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`db_apps`;  
CREATE TABLE `prs_sarbox_development`.`db_apps` (  
`id` int(11) NOT NULL auto\_increment,  
`db_id` int(11) default NULL,  
`app_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`db_svrs`;  
CREATE TABLE `prs_sarbox_development`.`db_svrs` (  
`id` int(11) NOT NULL auto\_increment,  
`db_id` int(11) default NULL,  
`server_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

When I try to open the URL:  
[http://192.168.2.148:3000/db\_apps](http://192.168.2.148:3000/db_apps)

I got the list of the content of the DB.

Db App  
15 1 Show Edit Destroy  
11 14 Show Edit Destroy  
22 23 Show Edit Destroy  
4 17 Show Edit Destroy  
4 21 Show Edit Destroy  
2 17 Show Edit Destroy  
2 21 Show Edit Destroy  
2 5 Show Edit Destroy  
2 19 Show Edit Destroy  
2 20 Show Edit Destroy

I would like to see instead of the ID of the DB or APP the Name that  
belongs to that Database of the Name of the Application from the DBs  
and Apps tables repectively. I might be missing something, when I  
create the migration run the rake db:migrate then later edit the model  
as follow:

app Model:  
####################  
class App \< ActiveRecord::Base

has\_many :servers, :through =\> :app\_svrs  
has\_many :dbs, :through =\> :db\_apps

end

app\_svr Model:  
####################  
class AppSvr \< ActiveRecord::Base

belongs\_to :app  
belongs\_to :server

end

db Model:  
####################  
class Db \< ActiveRecord::Base

has\_many :apps, :through =\> :db\_apps  
has\_many :servers, :through =\> :db\_servers

end

db\_app Model:  
####################  
class DbApp \< ActiveRecord::Base

belongs\_to :db  
belongs\_to :app

end

db\_svr Model:  
####################  
class DbSvr \< ActiveRecord::Base

belongs\_to :db  
belongs\_to :server

end

server Model:  
####################  
class Server \< ActiveRecord::Base

has\_many :apps, :through =\> :app\_svrs  
has\_many :dbs, :through =\> :db\_svrs

end

Also for Edit and Add, I would like to have a Select to limit only  
those values from the current values in the Database to avoid typo  
errors. and what I have is an textfield instead of a select box for  
the New or Edit forms.

### 

New db\_app  
Db \<input type = text… =\> Like to have a Select from the DB…  
App \<input type = text…  
Back

### 

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![Dinooz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@Dinooz](https://www.ruby-forum.com/u/Dinooz)\
**Post date:** [February 21, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/how-to-create-a-lov-list-of-values-in-a-rails-application/86345/3 "2007-02-21T18:45:22Z")

</div>

Thank you Mike for your reply here is layout of the current tables:  
3 Main tables: servers , dbs , apps [ For some reason  
scaffold\_resource did not like the work database/s application/s]

These 3 tables work together with the tables: app\_svrs, db\_apps and  
db\_svrs

DROP TABLE IF EXISTS `prs_sarbox_development`.`servers`;  
CREATE TABLE `prs_sarbox_development`.`servers` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`cat` varchar(255) default NULL,  
`net_face` int(11) default NULL,  
`ids` int(11) default NULL,  
`mon_man` int(11) default NULL,  
`mon_aut` int(11) default NULL,  
`int_ip` varchar(255) default NULL,  
`ext_ip` varchar(255) default NULL,  
`desc` varchar(255) default NULL,  
`bu_media` varchar(255) default NULL,  
`bu_method` varchar(255) default NULL,  
`bu_data_freq` varchar(255) default NULL,  
`os_vendor` varchar(255) default NULL,  
`os` varchar(255) default NULL,  
`os_version` varchar(255) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`dbs`;  
CREATE TABLE `prs_sarbox_development`.`dbs` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`cat` varchar(255) default NULL,  
`description` varchar(255) default NULL,  
`mon_man` int(11) default NULL,  
`mon_auto` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`apps`;  
CREATE TABLE `prs_sarbox_development`.`apps` (  
`id` int(11) NOT NULL auto\_increment,  
`name` varchar(255) default NULL,  
`fsa` int(11) default NULL,  
`fsa_logic` varchar(255) default NULL,  
`description` varchar(255) default NULL,  
`bu_data` varchar(255) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`app_svrs`;  
CREATE TABLE `prs_sarbox_development`.`app_svrs` (  
`id` int(11) NOT NULL auto\_increment,  
`server_id` int(11) default NULL,  
`app_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`db_apps`;  
CREATE TABLE `prs_sarbox_development`.`db_apps` (  
`id` int(11) NOT NULL auto\_increment,  
`db_id` int(11) default NULL,  
`app_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `prs_sarbox_development`.`db_svrs`;  
CREATE TABLE `prs_sarbox_development`.`db_svrs` (  
`id` int(11) NOT NULL auto\_increment,  
`db_id` int(11) default NULL,  
`server_id` int(11) default NULL,  
PRIMARY KEY (`id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

When I try to open the URL:  
[http://192.168.2.148:3000/db\_apps](http://192.168.2.148:3000/db_apps)

I got the list of the content of the DB.

Db App  
15 1 Show Edit Destroy  
11 14 Show Edit Destroy  
22 23 Show Edit Destroy  
4 17 Show Edit Destroy  
4 21 Show Edit Destroy  
2 17 Show Edit Destroy  
2 21 Show Edit Destroy  
2 5 Show Edit Destroy  
2 19 Show Edit Destroy  
2 20 Show Edit Destroy

I would like to see instead of the ID of the DB or APP the Name that  
belongs to that Database of the Name of the Application from the DBs  
and Apps tables repectively. I might be missing something, when I  
create the migration run the rake db:migrate then later edit the model  
as follow:

app Model:  
####################  
class App \< ActiveRecord::Base

has\_many :servers, :through =\> :app\_svrs  
has\_many :dbs, :through =\> :db\_apps

end

app\_svr Model:  
####################  
class AppSvr \< ActiveRecord::Base

belongs\_to :app  
belongs\_to :server

end

db Model:  
####################  
class Db \< ActiveRecord::Base

has\_many :apps, :through =\> :db\_apps  
has\_many :servers, :through =\> :db\_servers

end

db\_app Model:  
####################  
class DbApp \< ActiveRecord::Base

belongs\_to :db  
belongs\_to :app

end

db\_svr Model:  
####################  
class DbSvr \< ActiveRecord::Base

belongs\_to :db  
belongs\_to :server

end

server Model:  
####################  
class Server \< ActiveRecord::Base

has\_many :apps, :through =\> :app\_svrs  
has\_many :dbs, :through =\> :db\_svrs

end

Also for Edit and Add, I would like to have a Select to limit only  
those values from the current values in the Database to avoid typo  
errors. and what I have is an textfield instead of a select box for  
the New or Edit forms.

### 

New db\_app  
Db \<input type = text… =\> Like to have a Select from the DB…  
App \<input type = text…  
Back

### 

Thanks in advance for your help.
