mel ram
2008-Jan-13 07:06 UTC
Scaffolding w/ Rails 2.0 - Is there a way to do the models first?
I was playing around with the new scaffold generator and I noticed that if I generated a model first (which creates a migration) and updated the migration for the model... and then tried to do a scaffold of the model, the generator won''t create any usable views or controller. Essentially, it''s not reading the model or database when creating the scaffold. But if delete the model and the migration... and run the scaffold again w/ the data structure of the model specified, it will create a usable controller and views. <b>My questions is:</b> Is there a way to create the models first and then create the scaffolds... now that the old scaffold generator has been removed? ~ mel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Winkman
2008-Jan-13 08:01 UTC
Re: Scaffolding w/ Rails 2.0 - Is there a way to do the models first?
Hi Mel, I''m not really a rails pro, but from my understanding, if you create a new scaffold, the rails generators will automatically create a controller, model and scaffold/view. Fairly good in my view, but it does take some getting used to. For Example.... <code> rails testing cd testing ruby script/generate scaffold MODELNAME </code> (Of course replacing MODELNAME with a new model name (that hasn''t yet been created) like Products) This will create these files: exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/products exists app/views/layouts/ exists test/functional/ exists test/unit/ create app/views/products/index.html.erb create app/views/products/show.html.erb create app/views/products/new.html.erb create app/views/products/edit.html.erb create app/views/layouts/products.html.erb create public/stylesheets/scaffold.css dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/product.rb create test/unit/product_test.rb create test/fixtures/products.yml create db/migrate create db/migrate/001_create_products.rb create app/controllers/products_controller.rb create test/functional/products_controller_test.rb create app/helpers/products_helper.rb route map.resources :products Hope this answers your question... Mitch On Jan 13, 5:06 pm, mel ram <mel...-IA9i2KS8NFBpEKysQ+xqfPpXobYPEAuW@public.gmane.org> wrote:> I was playing around with the new scaffold generator and I noticed > that if I generated a model first (which creates a migration) and > updated the migration for the model... and then tried to do a scaffold > of the model, the generator won''t create any usable views or > controller. Essentially, it''s not reading the model or database when > creating the scaffold. > > But if delete the model and the migration... and run the scaffold > again w/ the data structure of the model specified, it will create a > usable controller and views. > > <b>My questions is:</b> Is there a way to create the models first and > then create the scaffolds... now that the old scaffold generator has > been removed? > > ~ mel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wildtangent
2008-Jan-13 16:49 UTC
Re: Scaffolding w/ Rails 2.0 - Is there a way to do the models first?
AFAIK, the scaffold generator will only generate the views based on what you provide it at the command line, If you''ve already created your model, don''t sweat! just add the field names and types when you generate the scaffold, choose No when it asks to overwrite your model migration and fixtures. It will generate the views based on what you provided it. e.g ruby script/generate scaffold name:string description:text category_id:integer would create the views with f.text_field(:name), f.text_area(:description) and (i wish) f.collection_select(:category_id, @categories, :id, :name) not that DRY a solution, but better than writing them yourself. Look into make_resourceful by hampton caitlin, which rocks as a replacement RESTful scaffold generator. Cheers, Joe On Jan 13, 8:01 am, Winkman <php.mi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Mel, > I''m not really a rails pro, but from my understanding, if you create a > new scaffold, the rails generators will automatically create a > controller, model and scaffold/view. > Fairly good in my view, but it does take some getting used to. > For Example.... > <code> > rails testing > cd testing > ruby script/generate scaffold MODELNAME > </code> > (Of course replacing MODELNAME with a new model name (that hasn''t yet > been created) like Products) > This will create these files: > exists app/models/ > exists app/controllers/ > exists app/helpers/ > create app/views/products > exists app/views/layouts/ > exists test/functional/ > exists test/unit/ > create app/views/products/index.html.erb > create app/views/products/show.html.erb > create app/views/products/new.html.erb > create app/views/products/edit.html.erb > create app/views/layouts/products.html.erb > create public/stylesheets/scaffold.css > dependency model > exists app/models/ > exists test/unit/ > exists test/fixtures/ > create app/models/product.rb > create test/unit/product_test.rb > create test/fixtures/products.yml > create db/migrate > create db/migrate/001_create_products.rb > create app/controllers/products_controller.rb > create test/functional/products_controller_test.rb > create app/helpers/products_helper.rb > route map.resources :products > > Hope this answers your question... > Mitch > > On Jan 13, 5:06 pm, mel ram <mel...-IA9i2KS8NFBpEKysQ+xqfPpXobYPEAuW@public.gmane.org> wrote: > > > I was playing around with the new scaffold generator and I noticed > > that if I generated a model first (which creates a migration) and > > updated the migration for the model... and then tried to do a scaffold > > of the model, the generator won''t create any usable views or > > controller. Essentially, it''s not reading the model or database when > > creating the scaffold. > > > But if delete the model and the migration... and run the scaffold > > again w/ the data structure of the model specified, it will create a > > usable controller and views. > > > <b>My questions is:</b> Is there a way to create the models first and > > then create the scaffolds... now that the old scaffold generator has > > been removed? > > > ~ mel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
mel ram
2008-Jan-13 21:23 UTC
Re: Scaffolding w/ Rails 2.0 - Is there a way to do the models first?
Thanks Joe. Good suggestion on just specifying the variables again and it wouldn''t be that big a deal except they are specified differently then in the migration... which means I have to do more than just copy/ pasting. It is better than creating it all by hand but hopeful they address this. I will check out make_resourceful. Hope that will address the issue. Thanks. ~ mel On Jan 13, 8:49 am, Wildtangent <wildtang...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> AFAIK, the scaffold generator will only generate the views based on > what you provide it at the command line, > > If you''ve already created your model, don''t sweat! just add the field > names and types when you generate the scaffold, choose No when it asks > to overwrite your model migration and fixtures. It will generate the > views based on what you provided it. > > e.g > ruby script/generate scaffold name:string description:text > category_id:integer > > would create the views with f.text_field(:name), > f.text_area(:description) and (i wish) > f.collection_select(:category_id, @categories, :id, :name) > > not that DRY a solution, but better than writing them yourself. Look > into make_resourceful by hampton caitlin, which rocks as a replacement > RESTful scaffold generator. > > Cheers, > Joe > > On Jan 13, 8:01 am, Winkman <php.mi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Mel, > > I''m not really a rails pro, but from my understanding, if you create a > > new scaffold, the rails generators will automatically create a > > controller, model and scaffold/view. > > Fairly good in my view, but it does take some getting used to. > > For Example.... > > <code> > > rails testing > > cd testing > > ruby script/generate scaffold MODELNAME > > </code> > > (Of course replacing MODELNAME with a new model name (that hasn''t yet > > been created) like Products) > > This will create these files: > > exists app/models/ > > exists app/controllers/ > > exists app/helpers/ > > create app/views/products > > exists app/views/layouts/ > > exists test/functional/ > > exists test/unit/ > > create app/views/products/index.html.erb > > create app/views/products/show.html.erb > > create app/views/products/new.html.erb > > create app/views/products/edit.html.erb > > create app/views/layouts/products.html.erb > > create public/stylesheets/scaffold.css > > dependency model > > exists app/models/ > > exists test/unit/ > > exists test/fixtures/ > > create app/models/product.rb > > create test/unit/product_test.rb > > create test/fixtures/products.yml > > create db/migrate > > create db/migrate/001_create_products.rb > > create app/controllers/products_controller.rb > > create test/functional/products_controller_test.rb > > create app/helpers/products_helper.rb > > route map.resources :products > > > Hope this answers your question... > > Mitch > > > On Jan 13, 5:06 pm, mel ram <mel...-IA9i2KS8NFBpEKysQ+xqfPpXobYPEAuW@public.gmane.org> wrote: > > > > I was playing around with the new scaffold generator and I noticed > > > that if I generated a model first (which creates a migration) and > > > updated the migration for the model... and then tried to do a scaffold > > > of the model, the generator won''t create any usable views or > > > controller. Essentially, it''s not reading the model or database when > > > creating the scaffold. > > > > But if delete the model and the migration... and run the scaffold > > > again w/ the data structure of the model specified, it will create a > > > usable controller and views. > > > > <b>My questions is:</b> Is there a way to create the models first and > > > then create the scaffolds... now that the old scaffold generator has > > > been removed? > > > > ~ mel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---