Hi, 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 tab le for your model (Assignment) Is this not possible in Rails? It would be *really* helpful for my application. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060309/c3e7c77c/attachment.html
I think you need to have a table called ''assignments'' Matt Larry White wrote:> Hi, > > 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 tab > le for your model (Assignment) > > Is this not possible in Rails? It would be *really* helpful for my > application. > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
there should be no problem, see this sample (just forget scaffolding for views): $ 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", "table_schema"=>"information_schema", "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, "user_defined_type_schema"=>nil}>>>So, just manually create AR model for your view and explicitly set_table_name of your view for it. On 3/9/06, Larry White <ljw1001@gmail.com> wrote:> Hi, > > 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 tab > le for your model (Assignment) > > Is this not possible in Rails? It would be *really* helpful for my > application. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Actually, it was a typo that caused the original problem. Rails works fine for reading from views. The one catch I saw was that the view needs to have the id column included if you want to ''show'' or ''edit'' the original items. On 3/9/06, Lugovoi Nikolai <meadow.nnick@gmail.com> wrote:> > there should be no problem, see this sample (just forget scaffolding for > views): > > $ 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", > "table_schema"=>"information_schema", > "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, > "user_defined_type_schema"=>nil}> > >> > > So, just manually create AR model for your view and explicitly > set_table_name of your view for it. > > On 3/9/06, Larry White <ljw1001@gmail.com> wrote: > > Hi, > > > > 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 tab > > le for your model (Assignment) > > > > Is this not possible in Rails? It would be *really* helpful for my > > application. > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060309/5dd738c4/attachment-0001.html