i know this may be easy, but i cant find how to do this.
i have a table called status_def
i want to generate a scaffold for it, but it will not let me create
one because (i think) the table name is not plural.
is there a command line option to script/generate that will allow me
to create a scaffold if the table is not plural ?
btw - all my other tables obey conventions nice, but too much code
will have to be re-written to change the name of this table.
next question.
one of the fields in the status_def table is oem. if i generate a
scaffold for this table, can i put something in the model that will
only allow records of oem = 'somecompany' to be selected ?
I think this is not really a problem with the scaffold but the model,
which will be pluralised by default.
Once you have generated your scaffold, edit the /app/models/
status_def.rb file to :
class StatusDef< ActiveRecord::Base
set_table_name "status_def"
end
I don't know the answer to your second question, but it implies there
is a related company. If this is the case you could use the ID of the
company when selecting from status_def. Maybe use act_as_list, or
scope would be useful here?
ok, well the reason i asked was because when i did the script/generate
scaffold status_def it spit out this
Before updating scaffolding from new DB schema, try creating a table
for your model (StatusDef)
and i do have the table in the database .
weird.
thanks, i found another way around the second question
sk
Ahh, opps, yes. The scaffold it built from the model, which is in
that naming format.
I know the capitals are a requirement of Ruby, but I am not sure about
the removal of underscores - probably convention again
Rails will pluralise the model name to guess the table name, so:
./script/generate scaffold status_def
model = StatusDef
DB table = statusdefs <- wrong in this case.
There does not seem to be a switch on generate to override this
behaviour, so you need to do it in three steps (punishment for going
outside the conventions) :
./script/generate model status_def
model = StatusDef
Edit the /app/models/status_def.rb file, add:
set_table_name "status_def"
thanks for the help, this table stands alone, no has_many, has_one,
hmbtm, etc... just all alone and a scaffold does all the CRUD i need.
i appreciate your help. Really, i was good on the other tables, really
i was, i even have the book ! don't know what i was thinking still,
but i am all up and running now.
thanks again