# Lookup tables and scaffolding

**URL:** <https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992>\
**Category:** Rails\
**Created:** [May 19, 2006, 3:11am UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992 "2006-05-19T03:11:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkadarusman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@jkadarusman](https://www.ruby-forum.com/u/jkadarusman)\
**Post date:** [May 19, 2006, 3:11am UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992/1 "2006-05-19T03:11:35Z")

</div>

It occurs to me as a missing feature that there’s no way to indicate a  
lookup  
table relationship (as opposed to other sorts of foreign key  
relationships)  
in Rails and that the scaffolding generator could recognise this lookup  
and  
render a drop-down list automagically for the lookup table.

Say you have an Address and a State, and the State is a lookup table.  
In  
addresses you have state\_id which points to one of the entries in  
states. In  
your models you represent this with the odd-sounding foreign key  
relationship  
calls:

class Address #…  
belongs\_to :state

And the even less meaningful:

class State #…  
has\_many :addresses

Obviously, the scaffolding cannot take any such relationship and produce  
a  
lookup dropdown, because it wouldn’t make sense in anything other than  
these  
sort of lookup table scenarios. So, perhaps there’s room for some  
alternative calls that the scaffolding generator could understand (and  
that  
would make more sense to write):

class Address #…  
includes\_a :state

class State #…  
is\_part\_of :addresses

I’m pretty new to RoR, so I wanted to fly this past the minds on this  
list  
before thinking about it too much more. Perhaps I’ve got a solution to  
a  
non-problem that I only think is a problem through my own ignorance. Or  
is  
this a worthwhile avenue to put some more effort into? What are your  
thoughts?

---

<div class="post-metadata">

**Author:** ![jkadarusman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@jkadarusman](https://www.ruby-forum.com/u/jkadarusman)\
**Post date:** [May 19, 2006, 3:29am UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992/2 "2006-05-19T03:29:55Z")

</div>

This is probably something that we all thought when first getting into  
RoR (which for me, wasn’t that long ago), but adding that sort of  
thing yourself isn’t difficult at all. Scaffolding is something rather  
cool that rails can do, but when it comes to real world applications,  
scaffolding alone doesn’t even nearly get the job done. Most people  
either don’t use scaffolding at all, or only use it to do the most  
basic parts of their project. What I’m trying to say is, you can put  
it off all you like, but sooner or later, you’re going to have to  
start learning to program in ruby.

As for your suggestion of includes\_a and is\_part\_of, I can’t see it  
becoming a core rails feature, but building a plugin like that might  
be an interesting project for someone.

-Nathan

---

<div class="post-metadata">

**Author:** ![jkadarusman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@jkadarusman](https://www.ruby-forum.com/u/jkadarusman)\
**Post date:** [May 22, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992/3 "2006-05-22T19:31:33Z")

</div>

On 5/18/06, Jason K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m pretty new to RoR, so I wanted to fly this past the minds on this list  
> before thinking about it too much more. Perhaps I’ve got a solution to a  
> non-problem that I only think is a problem through my own ignorance. Or is  
> this a worthwhile avenue to put some more effort into? What are your  
> thoughts?

Try the Scaffolding Extensions Plugin:  
[http://wiki.rubyonrails.com/rails/pages/Scaffolding+Extensions+Plugin](http://wiki.rubyonrails.com/rails/pages/Scaffolding+Extensions+Plugin)

---

<div class="post-metadata">

**Author:** ![jkadarusman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@jkadarusman](https://www.ruby-forum.com/u/jkadarusman)\
**Post date:** [May 22, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992/4 "2006-05-22T20:37:44Z")

</div>

You should also look at the ajax\_scaffold\_generator project:

[http://www.ajaxscaffold.com](http://www.ajaxscaffold.com)

It allows you to customize the scaffold to do lookup tables as well.

---

<div class="post-metadata">

**Author:** ![jkadarusman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@jkadarusman](https://www.ruby-forum.com/u/jkadarusman)\
**Post date:** [May 22, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/lookup-tables-and-scaffolding/60992/5 "2006-05-22T22:41:05Z")

</div>

Exactly.

The point of the scaffolds isn’t to write an app for you or design forms  
for you; hardly anyone really uses the scaffold-generated forms in any  
recognizabke form beyond the first half hour of a model’s life.

Scaffolding is less about generating code that does something than it is  
about relieving the tedium and niggling errors that would result if  
developers had to create all of the dozens to hundreds of initial, bare  
files that make up a Rails app by hand and stick them in all the right  
places.

Also bear in mind that scaffolds get generated _before_ you have a  
chance to establish relationships in the model as you propose. All the  
scaffold generator has to go on is foreign key ID fields and maybe a  
peek at the schema, and there’s no way to tell whether widget\_id is  
going to be pointing to a table that contains 20 widgets that would make  
for a nice select pulldown, or 20,000 widgets stocked in a supermarket,  
which may well crash a browser if fed into a select field.

unknown wrote:

> This is probably something that we all thought when first getting into  
> RoR (which for me, wasn’t that long ago), but adding that sort of  
> thing yourself isn’t difficult at all. Scaffolding is something rather  
> cool that rails can do, but when it comes to real world applications,  
> scaffolding alone doesn’t even nearly get the job done. Most people  
> either don’t use scaffolding at all, or only use it to do the most  
> basic parts of their project. What I’m trying to say is, you can put  
> it off all you like, but sooner or later, you’re going to have to  
> start learning to program in ruby.
> 
> As for your suggestion of includes\_a and is\_part\_of, I can’t see it  
> becoming a core rails feature, but building a plugin like that might  
> be an interesting project for someone.
> 
> -Nathan
