Steve Ross
Steve Ross

Reputation: 4144

Creating Rails Generator For Model/View/Controller/Mailer

I have an app that's heavily form-based. Many of the forms are constructed exactly alike so it seems like a natural fit for a generator. What I want to do is create one that works like this (fictitious example):

rails g request_form name:string phone:string date_of_birth:date

In any case, the standard, empty controllers, helpers, models, and so on won't quite do. I've read the Rails code but it's, frankly, not been a heck of a lot of help in puzzling this out. What I want to do specifically is:

I'm getting stalled at square 1: How the heck do I get the ARGV part of the rails g command -- that is, the field names? Then there's square 2: How do I hook into the built-in generators, where appropriate and fill in my own stuff where not?

This is analogous to

rails g scaffold blah:type blah1:type

so I don't think this is biting off more than I can chew...

Any help mucho appreciated!

Upvotes: 1

Views: 902

Answers (2)

Jeff Paquette
Jeff Paquette

Reputation: 7127

The awesome Ryan Bates has a screencast on writing generators in Rails 3, have you watched that?

Upvotes: 1

apneadiving
apneadiving

Reputation: 115521

All inspiration needed in this great gem: https://github.com/ryanb/nifty-generators

Upvotes: 1

Related Questions