# Thinking about tweaking some things

**URL:** <https://www.ruby-forum.com/t/thinking-about-tweaking-some-things/108035>\
**Category:** Rails\
**Created:** [June 28, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/thinking-about-tweaking-some-things/108035 "2007-06-28T16:21:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hotgazpacho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a587f6/32.png) [@hotgazpacho](https://www.ruby-forum.com/u/hotgazpacho)\
**Post date:** [June 28, 2007, 4:21pm UTC](https://www.ruby-forum.com/t/thinking-about-tweaking-some-things/108035/1 "2007-06-28T16:21:40Z")

</div>

Hello all,  
As I’ve gotten more comfortable using rails, I’ve noticed some things  
that I seem to be doing over and over. I think a fair number of the  
issues I run across have come about because the default scaffolding  
doesn’t quite do everything I want (although it is still pretty slick,  
nonetheless). I know scaffolding isn’t supposed to be the final code,  
but if I could do a few more things with it, I could probably keep more  
of what gets generated. I wanted to run these items by the group before  
I try to write scripts to handle them, as I imagine I’m probably not the  
first. Here’s the issues:

1. The model generator doesn’t infer relationships with other tables -  
it looks like it should be pretty straightforward to loop through the  
other tables and look for cases where a) tablename\_id is a field b) the  
current table contains the name of another table and id and c) where  
another table contains tablename\_id and another table’s id. In other  
words, I’d like it to infer the a) has\_many b) belongs\_to  
c)has\_and\_belongs\_to\_many relationships.
2. The code that generates the list view should:  
a) Loop through the table fields at generation time, rather than  
runtime.  
b) It should be smart enough to take any foreign key fields and make  
them point to a more descriptive value (in other words, it should pull  
back the name property from Customer instead of Customer\_id when  
displaying an invoice).  
c) The table should be given an appropriate CSS class, as should the  
headers, data fields, etc.
3. The code that generates the fields for the edit/list view should be  
improved by:  
a) If it sees something that appears to be a foreign key to another  
table, it should automatically generate a dropdown control for selecting  
the value in a more friendly way. You could have it pull in the name  
field automatically, for example.  
b) If it sees a boolean field, it should generate a checkbox  
c) If it sees a field named password, it should automatically make  
it a password textbox  
d) Would it be possible to make it load the associated model class  
dynamically as the script is running? If so, it might be possible to  
determine the items that are contained by object (has\_many  
relationships) and provide UI for them. You might even be able to do the  
same for has\_and\_belongs\_to\_many relationships.  
e) Long text fields should automatically get a Text Area control  
f) Fields should be enclosed in a fieldset, with an appropriate CSS  
class set for the fieldset and an appropriate legend (no underscores)  
g) Field labels should be actual labels, with the “for” attribute  
set for accessibility.

Does anyone have anything else they would add? Does anyone have fixes  
for the stuff I just listed?

Thanks,  
Will

* * *

Get the Yahoo! toolbar and be alerted to new email wherever you’re  
surfing.
