Hi, I''m trying to add a “Date available” column to a “Products” table. Here’s what I typed in and got back: ruby script/generate migration AddDate_availableToProducts date_available:datetime exists db/migrate create db/migrate/20080613112844_add_date_available_to_products.rb The db/migrate file seems to have been updated correctly: class AddDateAvailableToProducts def self.up add_column :products, :date_available, :datetime end def self.down remove_column :products, :date_available end end The Products db (in phpmyadmin) is showing the new column along with the existing ones. But the browser (http://localhost:3000/products) isn''t updating with the new column - it''s just showing the existing fields. I also ran rake db:migrate in case this would help and here''s what it returned: == 20080613112844 AddDateAvailableToProducts: migrating ======================-- add_column(:products, :date_available, :datetime) -> 0.5930s == 20080613112844 AddDateAvailableToProducts: migrated (0.5930s) ============= Any idea where I am going wrong? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-13 12:17 UTC
Re: Adding new column to table - browser not showing it
On 13 Jun 2008, at 13:11, Peter Donelan wrote:> > The Products db (in phpmyadmin) is showing the new column along with > the > existing ones. But the browser (http://localhost:3000/products) isn''t > updating with the new column - it''s just showing the existing > fields. I > also ran rake db:migrate in case this would help and here''s what it > returned: > > == 20080613112844 AddDateAvailableToProducts: migrating > ======================> -- add_column(:products, :date_available, :datetime) > -> 0.5930s > == 20080613112844 AddDateAvailableToProducts: migrated (0.5930s) > =============> > Any idea where I am going wrong? Thanks.Nowhere. if you looked at the view files in your rails app you''d see it''s just a static list of columns: you need to update the views. Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Donelan
2008-Jun-13 12:32 UTC
Re: Adding new column to table - browser not showing it
Frederick Cheung wrote:> Nowhere. if you looked at the view files in your rails app you''d see > it''s just a static list of columns: you need to update the views. > > FredThanks for your reply Fred. Sorry, but I''m not sure what you mean...how can I update the views? Cheers - Peter -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-13 12:53 UTC
Re: Adding new column to table - browser not showing it
On 13 Jun 2008, at 13:32, Peter Donelan wrote:> > Frederick Cheung wrote: >> Nowhere. if you looked at the view files in your rails app you''d see >> it''s just a static list of columns: you need to update the views. >> >> Fred > > Thanks for your reply Fred. Sorry, but I''m not sure what you > mean...how > can I update the views?You edit the corresponding files. Fred> > > Cheers - Peter > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Donelan
2008-Jun-13 13:25 UTC
Re: Adding new column to table - browser not showing it
>> Frederick Cheung wrote: >>> Nowhere. if you looked at the view files in your rails app you''d see >>> it''s just a static list of columns: you need to update the views. >>> >>> Fred >> >> Thanks for your reply Fred. Sorry, but I''m not sure what you >> mean...how >> can I update the views? > You edit the corresponding files. > > FredI presume what Fred means is to edit all the files in views/products. Well I haven''t actually written any code yet for this application, it has all been generated with the scaffold command. Since the application is still in the very early stages, is there not just a way to update the views with the scaffold again? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
cassiommc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-14 13:00 UTC
Re: Adding new column to table - browser not showing it
Once you have changed your table schema running a migration that added a new column to it, you can re-rerun the scaffold generation. It will ask you if it should replace existing files. On Jun 13, 10:25 am, Peter Donelan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> >> Frederick Cheung wrote: > >>> Nowhere. if you looked at the view files in your rails app you''d see > >>> it''s just a static list of columns: you need to update the views. > > >>> Fred > > >> Thanks for your reply Fred. Sorry, but I''m not sure what you > >> mean...how > >> can I update the views? > > You edit the corresponding files. > > > Fred > > I presume what Fred means is to edit all the files in views/products. > Well I haven''t actually written any code yet for this application, it > has all been generated with the scaffold command. Since the application > is still in the very early stages, is there not just a way to update the > views with the scaffold again? > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
To answer your above question, I think there is a plugin which contains the old facility for having a dynamic scaffold. However, just running the scaffold again will do the trick or simply looking through the code and reusing the examples you already have. I would take the latter route because you''ll get a better feel for how Rails handles things and how the code is put together. On Jun 14, 8:00 am, "cassio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <cassio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Once you have changed your table schema running a migration that added > a new column to it, you can re-rerun the scaffold generation. It will > ask you if it should replace existing files. > > On Jun 13, 10:25 am, Peter Donelan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > >> Frederick Cheung wrote: > > >>> Nowhere. if you looked at the view files in your rails app you''d see > > >>> it''s just a static list of columns: you need to update the views. > > > >>> Fred > > > >> Thanks for your reply Fred. Sorry, but I''m not sure what you > > >> mean...how > > >> can I update the views? > > > You edit the corresponding files. > > > > Fred > > > I presume what Fred means is to edit all the files in views/products. > > Well I haven''t actually written any code yet for this application, it > > has all been generated with the scaffold command. Since the application > > is still in the very early stages, is there not just a way to update the > > views with the scaffold again? > > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
YES , Bobnation is absolutely correct, the scaffold is nothing but creating CRUD depending upon the columns in the database. WHat Scaffold does is it maps the columns in database and created CRUD for it. So if you have added altered table by adding new column then replace those files by re-scaffolding. Hey try using active scaffold , its much better ........... On Jun 14, 7:51 pm, Bobnation <boblmart...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> To answer your above question, I think there is a plugin which > contains the old facility for having a dynamic scaffold. However, just > running the scaffold again will do the trick or simply looking through > the code and reusing the examples you already have. I would take the > latter route because you''ll get a better feel for how Rails handles > things and how the code is put together. > > On Jun 14, 8:00 am, "cassio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <cassio...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Once you have changed your table schema running a migration that added > > a new column to it, you can re-rerun the scaffold generation. It will > > ask you if it should replace existing files. > > > On Jun 13, 10:25 am, Peter Donelan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > >> Frederick Cheung wrote: > > > >>> Nowhere. if you looked at the view files in your rails app you''d see > > > >>> it''s just a static list of columns: you need to update the views. > > > > >>> Fred > > > > >> Thanks for your reply Fred. Sorry, but I''m not sure what you > > > >> mean...how > > > >> can I update the views? > > > > You edit the corresponding files. > > > > > Fred > > > > I presume what Fred means is to edit all the files in views/products. > > > Well I haven''t actually written any code yet for this application, it > > > has all been generated with the scaffold command. Since the application > > > is still in the very early stages, is there not just a way to update the > > > views with the scaffold again? > > > > -- > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Donelan
2008-Jun-15 16:10 UTC
Re: Adding new column to table - browser not showing it
Hey guys, thanks for the very useful advice. I tried editing the views and overwriting the scaffolding but received some errors (see below for details). So I destroyed the existing scaffold and generated a new one of the same name and now its working fine. Here are the errors I received: 1. When updating the views, there was a problem using the "datetime" data type for the "Date Available" field. On the Create/Update pages, the browser showed: "NoMethodError in Products#edit Showing products/edit.html.erb where line #28 raised: undefined method `datetime'' for #<ActionView::Helpers::FormBuilder:0x383a59c>" 2. When I tried to overwrite the existing Scaffold (ie. ruby script/generate scaffold Product), Command Prompt showed: "The name ''ProductsHelper'' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again." Its working now, but out of curiosity - any idea why these 2 errors happened? Thanks very much for your help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Donelan wrote:>>> Frederick Cheung wrote: >>>> Nowhere. if you looked at the view files in your rails app you''d see >>>> it''s just a static list of columns: you need to update the views. >>>> >>>> Fred >>> >>> Thanks for your reply Fred. Sorry, but I''m not sure what you >>> mean...how >>> can I update the views? >> You edit the corresponding files. >> >> Fred > > I presume what Fred means is to edit all the files in views/products. > Well I haven''t actually written any code yet for this application, it > has all been generated with the scaffold command. Since the application > is still in the very early stages, is there not just a way to update the > views with the scaffold again?Peter: if it used scaffold, once you migrate the database, you need to add the new column you want to see on the html table in your controller: class ProductsController < ApplicationController layout "default" #or whatever your current layout active_scaffold :products do |config| config.list.columns = [ :your_existing_fields, ..., :date_available ] ... end end Hope this helps. Daniel -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ruby script/scaffold no longer looks at the db to build the pages. It looks at what''s on the commandline passed as arguments. So running scaffold again can break stuff because it will try to create a migration that''s already there unless you tell it to skip that part. You can redo those files with ruby script/scaffold project name:string description:text started_on:datetime ended_on:datetime estimated_hours:decimal --skip-migration But generally, it''s considered best practice to not use scaffolding at all and get comfortable actually working with the form helpers. Adding a column is trivial. If you''re really lazy (like me) you could install my gem called scaffold_form sudo gem install scaffold_form_generator This generator creates the new and edit pages by looking at your database table directly, the way Rails used to do it. It doesn''t do the list or the show pages because I didn''t think that was necessary. Form generation is nice because it''s often time-consuming. However, this is still cheating, and not meant for production. :) (pass the model and controller name to the generator) ruby script/generate scaffold_form Project projects See http://scaffoldform.rubyforge.org/ for more. On Wed, Jul 9, 2008 at 11:43 AM, Daniel Zane < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Peter Donelan wrote: > >>> Frederick Cheung wrote: > >>>> Nowhere. if you looked at the view files in your rails app you''d see > >>>> it''s just a static list of columns: you need to update the views. > >>>> > >>>> Fred > >>> > >>> Thanks for your reply Fred. Sorry, but I''m not sure what you > >>> mean...how > >>> can I update the views? > >> You edit the corresponding files. > >> > >> Fred > > > > I presume what Fred means is to edit all the files in views/products. > > Well I haven''t actually written any code yet for this application, it > > has all been generated with the scaffold command. Since the application > > is still in the very early stages, is there not just a way to update the > > views with the scaffold again? > > Peter: if it used scaffold, once you migrate the database, you need to > add the new column you want to see on the html table in your controller: > > class ProductsController < ApplicationController > layout "default" #or whatever your current layout > > active_scaffold :products do |config| > config.list.columns = [ :your_existing_fields, ..., > :date_available ] > ... > end > end > > Hope this helps. > > Daniel > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---