RE: Problem with scaffolding and table name


#1

Hey Kostas,

I think this will help you :slight_smile:

http://wiki.rubyonrails.com/rails/pages/HowToUseLegacySchemas

Basically, you use:
class Entity < ActiveRecord::Base
set_table_name “entity”
end

Brian


#2

The problem is still that since scaffolding script fails, no rhtml
templates are being produced.


#3

On 3/10/06, Kostas K. removed_email_address@domain.invalid wrote:

The problem is still that since scaffolding script fails, no rhtml
templates are being produced.

So, what are the error messages then?


#4

Kostas K. wrote:

scripts/generate scaffold incident_reported

----> error Before updating scaffolding from new DB schema, try
creating a table for your model (IncidentReported)

I think it has to do with rails assuming the table is named
‘incident_reporteds’ which is wrong.
I was asking how i could inform rails’ scaffolding operation that my
table is named ‘incidents_reported’

Juan Lupi�n wrote:

if it is really so, it should help to set the table name in the
IncidentReported model:
set_table_name “incidents_reported”


Agnieszka F.


#5

scripts/generate scaffold incident_reported

----> error Before updating scaffolding from new DB schema, try
creating a table for your model (IncidentReported)

I think it has to do with rails assuming the table is named
‘incident_reporteds’ which is wrong.
I was asking how i could inform rails’ scaffolding operation that my
table is named ‘incidents_reported’

Juan Lupión wrote:


#6

On Fri, Mar 10, 2006 at 01:22:13PM +0200, Kostas K. wrote:
} scripts/generate scaffold incident_reported
}
} ----> error Before updating scaffolding from new DB schema, try
} creating a table for your model (IncidentReported)
}
} I think it has to do with rails assuming the table is named
} ‘incident_reporteds’ which is wrong.
} I was asking how i could inform rails’ scaffolding operation that my
} table is named ‘incidents_reported’

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|
inflect.irregular ‘incident_reported’, ‘incidents_reported’
end

–Greg


#7

Thanks a lot. It worked smoothly :slight_smile:


#8

Kostas K. wrote:

Thanks a lot. It worked smoothly :slight_smile:

I have same problem with legacy table name and can not figure out how to
make scaffold work

e.g

I have table name ‘ACTIVETASK’ and model ActiveTask

require ‘composite_primary_keys’
class ActiveTask < ActiveRecord::Base
set_table_name :ACTIVETASK
set_primary_keys :id, :site_id
end

my config/environment.rb

Inflector.inflections do |inflect|
inflect.irregular ‘ActiveTask’, ‘activetask’
inflect.uncountable ‘ActiveTask’
end