Ruby rails: script/generate scaffold error

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:


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

<span class="moz-txt-tag">|</span>inflect<span class="moz-txt-tag">|</span>

inflect.irregular ‘incident_reported’, ‘incidents_reported’

I have tested it and it works just fine 🙂
Keep coding.

One thought on “Ruby rails: script/generate scaffold error”

Comments are closed.