Forum: Rails Engines development Help with a noob

08ea9d1a897bec5ed5c02ed31dae12b8?d=identicon&s=25 Todd Nine (Guest)
on 2008-02-10 19:57
(Received via mailing list)
Hi all,
  I'm a noob to creating my own plugins, and I could use a hand.  I've
developed basic rails apps, and several advanced J2EE apps.  I
how my plugin structure mirrors the rails app mvc in the base app, but
having trouble with creating my models.  I created a new plugin via
"script/generate plugin projects_ranking".  I'd like to create the model
my database migration, but I don't know the command for generating a
within a plugin?  Where can I find documentation on generating models
a plugin?

E862fb7db4f79f9f6a241c37094e290d?d=identicon&s=25 Rob Morris (Guest)
on 2008-02-11 02:37
(Received via mailing list)
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


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.


This topic is locked and can not be replied to.