# \[N00b\] Can I generate a model file from \[sql\] table?

**URL:** <https://www.ruby-forum.com/t/n00b-can-i-generate-a-model-file-from-sql-table/154801>\
**Category:** Rails\
**Created:** [December 4, 2008, 3:06am UTC](https://www.ruby-forum.com/t/n00b-can-i-generate-a-model-file-from-sql-table/154801 "2008-12-04T03:06:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [December 4, 2008, 3:06am UTC](https://www.ruby-forum.com/t/n00b-can-i-generate-a-model-file-from-sql-table/154801/1 "2008-12-04T03:06:55Z")

</div>

Ah, it’s been a while since I’ve done any rails – I almost forgot how  
deceptively easy it is…

…to get yourself totally lost 😉

Anyway, I probably did this all backwards, but I created my table by  
writing a migration file, then rake db:migrate. So far, so good. I  
even whipped up a quick script to grind through some tab-separated text  
and fill the table – yay.

…But I seem to have forgotten the format for a model file, and I was  
thinking it sure would be handy if I could just point some generator or  
similar helper-script at the sql table and say “make me a model file  
that looks like that.”

About what do I want to read more? (Already trying to find all my old  
tutorials that include how to write a model file – I mean in terms of  
“does it for you” scripts :D)

Thanks!

---

<div class="post-metadata">

**Author:** ![olie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c4cdca/32.png) [@olie](https://www.ruby-forum.com/u/olie)\
**Post date:** [December 4, 2008, 3:38am UTC](https://www.ruby-forum.com/t/n00b-can-i-generate-a-model-file-from-sql-table/154801/2 "2008-12-04T03:38:49Z")

</div>

Hi Olie,

Olie D. wrote:

> …But I seem to have forgotten the format for a model file,

Perhaps the easiest thing to do to stimulate your memory might be to  
scaffold yourself a sandbox app. For the quick fix, just create a file  
named ‘singular\_version\_of\_your\_table\_name.rb’ with the following,  
minimim,  
content.

class SingularVersionOfYourTableName \< ActiveRecord::Base  
end

HTH,  
Bill
