Forum: Ruby on Rails Building a model from a database view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Larry W. (Guest)
on 2006-03-09 18:31
(Received via mailing list)

I'm trying to use rails to build a model from a database view.

I get this output

C:\dev\v6\project>ruby script/generate scaffold Assignment
       error  Before updating scaffolding from new DB schema, try
creating a
le for your model (Assignment)

Is this not possible in Rails?  It would be *really* helpful for my
Matthias von Rohr (Guest)
on 2006-03-09 18:37
(Received via mailing list)
I think you need to have a table called 'assignments'

Lugovoi N. (Guest)
on 2006-03-09 18:40
(Received via mailing list)
there should be no problem, see this sample (just forget scaffolding for

$ ruby script/console
Loading development environment.
>> class InfoSchemaTable < ActiveRecord::Base
>>   set_table_name 'information_schema.tables'
>> end
=> nil
>> InfoSchemaTable.find(:first, :conditions => "table_name = 'tables'")
=> #<InfoSchemaTable:0xf683aadc @attributes={"table_type"=>"VIEW",
"user_defined_type_catalog"=>nil, "reference_generation"=>nil,
"self_referencing_column_name"=>nil, "table_name"=>"tables",
"table_catalog"=>"dl_v03_dev", "user_defined_name"=>nil,

So, just manually create AR model for your view and explicitly
set_table_name of your view for it.
Larry W. (Guest)
on 2006-03-09 20:40
(Received via mailing list)
Actually, it was a typo that caused the original problem. Rails works
for reading from views. The one catch I saw was that the view needs to
the id column included if you want to 'show' or 'edit' the original
This topic is locked and can not be replied to.