# Help with a noob

**URL:** <https://www.ruby-forum.com/t/help-with-a-noob/128707>\
**Category:** Engines Development\
**Created:** [February 10, 2008, 7:57pm UTC](https://www.ruby-forum.com/t/help-with-a-noob/128707 "2008-02-10T19:57:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [February 10, 2008, 7:57pm UTC](https://www.ruby-forum.com/t/help-with-a-noob/128707/1 "2008-02-10T19:57:03Z")

</div>

Hi all,  
I’m a noob to creating my own plugins, and I could use a hand. I’ve  
only  
developed basic rails apps, and several advanced J2EE apps. I  
understand  
how my plugin structure mirrors the rails app mvc in the base app, but  
I’m  
having trouble with creating my models. I created a new plugin via  
“script/generate plugin projects\_ranking”. I’d like to create the model  
for  
my database migration, but I don’t know the command for generating a  
model  
within a plugin? Where can I find documentation on generating models  
within  
a plugin?

thanks,  
Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [February 11, 2008, 2:37am UTC](https://www.ruby-forum.com/t/help-with-a-noob/128707/2 "2008-02-11T02:37:53Z")

</div>

Hey Todd, welcome to Rails plugin development. 🙂

Basically, a model is just a class derived from ActiveRecord::Base, so,  
the class file itself is just

class FooModel \< ActiveRecord::Base

end

I don’t bother with script/generate for models, for this reason. It’s  
too simple.

The hard part is then building the migration to set up the database  
table foo\_models. I’m assuming you’re familiar with migrations, so the  
only tricky part is how you add them from a plugin.

Go to your plugin’s root directory, and add a directory ‘db’, then a  
subdir of that named ‘migrate’. Add your migration(s) there.

Once you’re happy with your initial migration, go to your Rails root  
dir, and run: ./script/generate plugin\_migration

That will add a new migration in your main rails app (basically a  
wrapper) for upgrading to add your plugin migration(s). You can check  
out what is generated by going to RAILS\_ROOT/db/migrate, and editing the  
newly created file. It’s just a proxy call that asks the plugin to  
migrate to a particular version.

Then rake db:migrate from your rails root like normal, and your new  
schema is in place, and your new model will pull from it, and be  
available throughout your app.

Cheers!

-Rob
