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
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.