While working on a ruby rails project, i stumbled in the following problem. I was trying to create a scaffold for a model (a ruby class representing a row in a DB table). I used the following code:
#script/generate scaffold incident_reported
incident_reported –> is the name of my model
Ruby rails framework makes certain assumptions based on the model name you provide. So in the above example it assumes that my table in the DB is named ‘incident_reporteds’, which of course was wrong. The error i got for running the above script was:
error Before updating scaffolding from new DB schema, try creating a table for your model (IncidentReported)
As a result of the error no *.rhtml templates were produced, which of course was frustrating. I could ignore this and simply create the *.rhtml templates myself. All i had to do was add the following line into my model’s class:
set_table_name(“Incidents_Reported”)
and simply write the *.rhtml files by hand.
Many thanks to Gregory Seidman for the solution he provided me in rail’s mailing list. Here it is:
Toward the end of your config/environment.rb there should be a commented
out section on inflections. You want something like this:
Inflector.inflections do
inflect.irregular ‘incident_reported’, ‘incidents_reported’
end
I have tested it and it works just fine 🙂
Keep coding.