Forum: Ruby on Rails accessing database model from generator?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
stewbawka (Guest)
on 2009-05-06 21:50
(Received via mailing list)
i'm writing my own generator :) basically a custom scaffolding type
thing to make my life easier when creating new resources.

instead of doing something like script/generate custom_scaffold
MyResource name:string description:string ... i decided to store all
the metadata about the tables and fields in the db.

my generator creates the model stub files when given a name that
corresponds to a table that already exists and which has metadata in
the database. i would like to check in my generator code if metadata
exists for the table in the DB before going ahead and creating all the
views, model, controller, etc..

i'm  not sure if this is kosher rails coding to have a generator that
depends on the existence of specifc models/tables to work.. but this
is just for me and i will make sure they are there whenever i use it..

any ideas?

another question.. i have a "m.route_resources file_name.pluralize"
line in my generator manifest.. is there anyway i can easily check if
the route already exists? if i run my generator multiple times (which
is gonna happen a lot since its still in the works) it keeps adding
duplicate routes in my routes.rb.

Thanks!! happy coding everyone :)

Stuart
stewbawka (Guest)
on 2009-05-06 23:27
(Received via mailing list)
looks like i have a knack for asking dumb questions.. you can just go
ahead and use the models :P

anybody got a handle on how to check if a resource route already
exists in routes.rb?

Stuart
This topic is locked and can not be replied to.