Hello ! I need your help ''cause I''ve got the Rails book (V.1) since yesterday and I''m following the examples. All was working fine until I wrote the empty! method. I wrote it in app/models/cart.rb like this : def empty! @items = [] @total_price = 0.0 end and I want to use it in app/controllers/store_controller.rb. I''m trying this way : def empty_cart find_cart.empty! flash[:notice] = ''Your cart is now empty'' redirect_to(:action => ''index'') end but when I go to http://localhost/store/empty_cart Rails tells me : NoMethodError in Store#empty_cart undefined method `empty!'' for #<Cart:0x40be4800> /app/controllers/store_controller.rb:28:in `empty_cart'' ./script/server:49 and I really don''t understand why ... Other methods available in cart.rb work well in store_controller ... Any idea ? Good evening. -- Nicolas Cavigneaux | GPG KeyID : CFE76D24 nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit :> Hello ! > > I need your help ''cause I''ve got the Rails book (V.1) since yesterday > and I''m following the examples. All was working fine until I wrote the > empty! method. I wrote it in app/models/cart.rb like this : > > def empty! > @items = [] > @total_price = 0.0 > end > > and I want to use it in app/controllers/store_controller.rb. I''m trying > this way : > > def empty_cart > find_cart.empty! > flash[:notice] = ''Your cart is now empty'' > redirect_to(:action => ''index'') > end > > but when I go to http://localhost/store/empty_cart Rails tells me : > > NoMethodError in Store#empty_cart > undefined method `empty!'' for #<Cart:0x40be4800> > /app/controllers/store_controller.rb:28:in `empty_cart'' > ./script/server:49 > > and I really don''t understand why ... > > Other methods available in cart.rb work well in store_controller ... > > Any idea ?Don''t know why but after a Webrick restart all is working well ... I''m using development mode, it should automatically reload files that have changed ... See you. -- Nicolas Cavigneaux | GPG KeyID : CFE76D24 nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Make sure that your empty! method is not below the private declaration. On 8/27/05, Nicolas Cavigneaux <nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org> wrote:> Hello ! > > I need your help ''cause I''ve got the Rails book (V.1) since yesterday > and I''m following the examples. All was working fine until I wrote the > empty! method. I wrote it in app/models/cart.rb like this : > > def empty! > @items = [] > @total_price = 0.0 > end > > and I want to use it in app/controllers/store_controller.rb. I''m trying > this way : > > def empty_cart > find_cart.empty! > flash[:notice] = ''Your cart is now empty'' > redirect_to(:action => ''index'') > end > > but when I go to http://localhost/store/empty_cart Rails tells me : > > NoMethodError in Store#empty_cart > undefined method `empty!'' for #<Cart:0x40be4800> > /app/controllers/store_controller.rb:28:in `empty_cart'' > ./script/server:49 > > and I really don''t understand why ... > > Other methods available in cart.rb work well in store_controller ... > > Any idea ? > > Good evening. > -- > Nicolas Cavigneaux | GPG KeyID : CFE76D24 > nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQBDEL+hcsG2ks/nbSQRAlnhAJ4utVWQAZkA/qcEtO6lxwjgcgwoqwCgvHMf > CW2JZZ01lRf4q6r0Nl0Ebr8> =wZaY > -----END PGP SIGNATURE----- > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
> I need your help ''cause I''ve got the Rails book (V.1) since yesterday > and I''m following the examples. All was working fine until I wrote the > empty! method. I wrote it in app/models/cart.rb like this : > > def empty! > @items = [] > @total_price = 0.0 > end >> and I want to use it in app/controllers/store_controller.rb. I''m > trying > this way : > > def empty_cart > find_cart.empty! > flash[:notice] = ''Your cart is now empty'' > redirect_to(:action => ''index'') > endThat code is correct and should work. Any chance you''ve accidentally got your empty! method marked as "private"?
On 28 Aug 2005, at 8:36 am, Nicolas Cavigneaux wrote:> Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit : > >> Hello ! >> >> I need your help ''cause I''ve got the Rails book (V.1) since yesterday >> and I''m following the examples. All was working fine until I wrote >> the >> empty! method. I wrote it in app/models/cart.rb like this : >> >> def empty! >> @items = [] >> @total_price = 0.0 >> end >> >> and I want to use it in app/controllers/store_controller.rb. I''m >> trying >> this way : >> >> def empty_cart >> find_cart.empty! >> flash[:notice] = ''Your cart is now empty'' >> redirect_to(:action => ''index'') >> end >> >> but when I go to http://localhost/store/empty_cart Rails tells me : >> >> NoMethodError in Store#empty_cart >> undefined method `empty!'' for #<Cart:0x40be4800> >> /app/controllers/store_controller.rb:28:in `empty_cart'' >> ./script/server:49 >> >> and I really don''t understand why ... >> >> Other methods available in cart.rb work well in store_controller ... >> >> Any idea ? >> > > Don''t know why but after a Webrick restart all is working well ... I''m > using development mode, it should automatically reload files that have > changed ...I got this too. It''s probably because your cart object is actually being stored in the session (i.e. the object''s been serialised into text and stored in a little file in your /tmp directory). Even if you add a method in your cart.rb file, any sessions left over from before you made the change will still have the ''old'' cart object, which doesn''t have an empty! method. Other ways of fixing it include deleting all the Ruby session files in /tmp, or clearing your browser''s cookie. There''s a write-up about this problem later in the book, on page 315. Hope that helps! Chris
The rule is pretty simple: If something inexplicable and weird happens, the first thing to do it to restart WEBrick. There are many things that can''t or just won''t change dynamically and some of them are not obvious. N. Nicolas Cavigneaux wrote:> Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit : > >>Hello ! >> >>I need your help ''cause I''ve got the Rails book (V.1) since yesterday >>and I''m following the examples. All was working fine until I wrote the >>empty! method. I wrote it in app/models/cart.rb like this : >> >> def empty! >> @items = [] >> @total_price = 0.0 >> end >> >>and I want to use it in app/controllers/store_controller.rb. I''m trying >>this way : >> >> def empty_cart >> find_cart.empty! >> flash[:notice] = ''Your cart is now empty'' >> redirect_to(:action => ''index'') >> end >> >>but when I go to http://localhost/store/empty_cart Rails tells me : >> >>NoMethodError in Store#empty_cart >>undefined method `empty!'' for #<Cart:0x40be4800> >>/app/controllers/store_controller.rb:28:in `empty_cart'' >>./script/server:49 >> >>and I really don''t understand why ... >> >>Other methods available in cart.rb work well in store_controller ... >> >>Any idea ? > > > Don''t know why but after a Webrick restart all is working well ... I''m > using development mode, it should automatically reload files that have > changed ... > > See you. > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Nicolas Cavigneaux wrote:> Don''t know why but after a Webrick restart all is working well ... I''m > using development mode, it should automatically reload files that have > changed ...WEBrick is weird, very weird. I often find that I have to restart it after code errors once I''ve fixed the error (and I''m definitely in development mode). Without restarting WEBrick, the error quite often stays - I have no idea why, but it''s quite frustrating sometimes! Anyone got any tips for fixing that? ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
Le dimanche 28 août 2005 à 08:36 -0400, Ken Barker a écrit :> Make sure that your empty! method is not below the private declaration.That was in fact because a session was already available for my user and this session was not updated with the new features. To fix it I had to delete my session file (on the server) or my cookie. Bye. -- Nicolas Cavigneaux | GPG KeyID : CFE76D24 nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Le dimanche 28 août 2005 à 20:58 +0100, Chris Mear a écrit :> I got this too. It''s probably because your cart object is actually > being stored in the session (i.e. the object''s been serialised into > text and stored in a little file in your /tmp directory). Even if you > add a method in your cart.rb file, any sessions left over from before > you made the change will still have the ''old'' cart object, which > doesn''t have an empty! method. > > Other ways of fixing it include deleting all the Ruby session files > in /tmp, or clearing your browser''s cookie. > > There''s a write-up about this problem later in the book, on page 315.This the good explanation :-) Thank you for help. -- Nicolas Cavigneaux | GPG KeyID : CFE76D24 nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Amen! And so I''ve learned the hard way. There has been moments where I have really been stuck trying to find a problem, and then finally restarted WEBrick... As a last resort back then, whereas I now restart it *often*. Oh a bug? If I don''t immediately understand what the problem is the first thing I do is to restart WEBrick... :) BTW: This probably should be mentioned somewhere in the docs, maybe on the wiki? Someplace really easily accessible, just to make sure that newbies using WEBrick have a chance of being notified. Otherwise WEBrick is great for development purposes on my win box. ------------------------------------------------------------------------ /*Ronny Hanssen*/ nikolaus heger wrote:> The rule is pretty simple: > > If something inexplicable and weird happens, the first thing to do it to > restart WEBrick. > > There are many things that can''t or just won''t change dynamically and > some of them are not obvious. > > N. > > Nicolas Cavigneaux wrote: > >> Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit : >> >>> Hello ! >>> >>> I need your help ''cause I''ve got the Rails book (V.1) since yesterday >>> and I''m following the examples. All was working fine until I wrote the >>> empty! method. I wrote it in app/models/cart.rb like this : >>> >>> def empty! >>> @items = [] >>> @total_price = 0.0 >>> end >>> >>> and I want to use it in app/controllers/store_controller.rb. I''m trying >>> this way : >>> >>> def empty_cart >>> find_cart.empty! >>> flash[:notice] = ''Your cart is now empty'' >>> redirect_to(:action => ''index'') >>> end >>> >>> but when I go to http://localhost/store/empty_cart Rails tells me : >>> >>> NoMethodError in Store#empty_cart >>> undefined method `empty!'' for #<Cart:0x40be4800> >>> /app/controllers/store_controller.rb:28:in `empty_cart'' >>> ./script/server:49 >>> >>> and I really don''t understand why ... >>> >>> Other methods available in cart.rb work well in store_controller ... >>> >>> Any idea ? >> >> >> >> Don''t know why but after a Webrick restart all is working well ... I''m >> using development mode, it should automatically reload files that have >> changed ... >> >> See you. >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I got sick of going in to clear out my cookies for this same reason, so I took 5 minutes and created a bookmark to do the same: javascript:eval("function uncookie(){ var dt = new Date(); dt.setYear(1975); dt = dt.toGMTString(); var cks = ('' '' + document.cookie).split(''=''); for(var i=0;i<cks.length; i++) { document.cookie = cks[i].substr(cks[i].indexOf('' '')) + ''=null; expires='' + dt; } alert(''All cookies cleared.''); }; uncookie();") On 8/29/05, Nicolas Cavigneaux <nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org> wrote:> Le dimanche 28 août 2005 à 20:58 +0100, Chris Mear a écrit : > > I got this too. It''s probably because your cart object is actually > > being stored in the session (i.e. the object''s been serialised into > > text and stored in a little file in your /tmp directory). Even if you > > add a method in your cart.rb file, any sessions left over from before > > you made the change will still have the ''old'' cart object, which > > doesn''t have an empty! method. > > > > Other ways of fixing it include deleting all the Ruby session files > > in /tmp, or clearing your browser''s cookie. > > > > There''s a write-up about this problem later in the book, on page 315. > > This the good explanation :-) Thank you for help. > -- > Nicolas Cavigneaux | GPG KeyID : CFE76D24 > nico-DRabjd/C3MEdnm+yROfE0A@public.gmane.org | http://www.bounga.org > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.1 (GNU/Linux) > > iD8DBQBDEzR9csG2ks/nbSQRAkT5AJ9N+qvcGkkRGNT8AMWM3RmjeHwN5gCeItr5 > bmtrlVxighGxpc7+hnhYPT8> =gXW6 > -----END PGP SIGNATURE----- > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Brock Weaver [OBC]Technique
On 8/29/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote:> Amen! > > And so I''ve learned the hard way. There has been moments where I have > really been stuck trying to find a problem, and then finally restarted > WEBrick... As a last resort back then, whereas I now restart it *often*. > Oh a bug? If I don''t immediately understand what the problem is the > first thing I do is to restart WEBrick... :) > > BTW: This probably should be mentioned somewhere in the docs, maybe on > the wiki? Someplace really easily accessible, just to make sure that > newbies using WEBrick have a chance of being notified. > > Otherwise WEBrick is great for development purposes on my win box.Can someone clarify when you need to restart webrick? The only time I''ve needed to is when I was changing a class that wasn''t part of ActiveRecord, and I was just require''ing it instead of using require_dependency.> ------------------------------------------------------------------------ > /*Ronny Hanssen*/ > > > nikolaus heger wrote: > > The rule is pretty simple: > > > > If something inexplicable and weird happens, the first thing to do it to > > restart WEBrick. > > > > There are many things that can''t or just won''t change dynamically and > > some of them are not obvious. > > > > N. > > > > Nicolas Cavigneaux wrote: > > > >> Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit : > >> > >>> Hello ! > >>> > >>> I need your help ''cause I''ve got the Rails book (V.1) since yesterday > >>> and I''m following the examples. All was working fine until I wrote the > >>> empty! method. I wrote it in app/models/cart.rb like this : > >>> > >>> def empty! > >>> @items = [] > >>> @total_price = 0.0 > >>> end > >>> > >>> and I want to use it in app/controllers/store_controller.rb. I''m trying > >>> this way : > >>> > >>> def empty_cart > >>> find_cart.empty! > >>> flash[:notice] = ''Your cart is now empty'' > >>> redirect_to(:action => ''index'') > >>> end > >>> > >>> but when I go to http://localhost/store/empty_cart Rails tells me : > >>> > >>> NoMethodError in Store#empty_cart > >>> undefined method `empty!'' for #<Cart:0x40be4800> > >>> /app/controllers/store_controller.rb:28:in `empty_cart'' > >>> ./script/server:49 > >>> > >>> and I really don''t understand why ... > >>> > >>> Other methods available in cart.rb work well in store_controller ... > >>> > >>> Any idea ? > >> > >> > >> > >> Don''t know why but after a Webrick restart all is working well ... I''m > >> using development mode, it should automatically reload files that have > >> changed ... > >> > >> See you. > >> > >> > >> ------------------------------------------------------------------------ > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
There are some good tips in this thread. I would be surprised if there was a list somewhere describing every case where you''d want to restart webrick. I just keep coding, and when I stumble across a bug that I don''t understand I restart webrick. ------------------------------------------------------------------------ /*Ronny Hanssen*/ Joe Van Dyk wrote:> On 8/29/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote: > >>Amen! >> >>And so I''ve learned the hard way. There has been moments where I have >>really been stuck trying to find a problem, and then finally restarted >>WEBrick... As a last resort back then, whereas I now restart it *often*. >>Oh a bug? If I don''t immediately understand what the problem is the >>first thing I do is to restart WEBrick... :) >> >>BTW: This probably should be mentioned somewhere in the docs, maybe on >>the wiki? Someplace really easily accessible, just to make sure that >>newbies using WEBrick have a chance of being notified. >> >>Otherwise WEBrick is great for development purposes on my win box. > > > Can someone clarify when you need to restart webrick? > > The only time I''ve needed to is when I was changing a class that > wasn''t part of ActiveRecord, and I was just require''ing it instead of > using require_dependency. > > >>------------------------------------------------------------------------ >>/*Ronny Hanssen*/ >> >> >>nikolaus heger wrote: >> >>>The rule is pretty simple: >>> >>>If something inexplicable and weird happens, the first thing to do it to >>>restart WEBrick. >>> >>>There are many things that can''t or just won''t change dynamically and >>>some of them are not obvious. >>> >>> N. >>> >>>Nicolas Cavigneaux wrote: >>> >>> >>>>Le samedi 27 août 2005 à 21:31 +0200, Nicolas Cavigneaux a écrit : >>>> >>>> >>>>>Hello ! >>>>> >>>>>I need your help ''cause I''ve got the Rails book (V.1) since yesterday >>>>>and I''m following the examples. All was working fine until I wrote the >>>>>empty! method. I wrote it in app/models/cart.rb like this : >>>>> >>>>> def empty! >>>>> @items = [] >>>>> @total_price = 0.0 >>>>> end >>>>> >>>>>and I want to use it in app/controllers/store_controller.rb. I''m trying >>>>>this way : >>>>> >>>>> def empty_cart >>>>> find_cart.empty! >>>>> flash[:notice] = ''Your cart is now empty'' >>>>> redirect_to(:action => ''index'') >>>>> end >>>>> >>>>>but when I go to http://localhost/store/empty_cart Rails tells me : >>>>> >>>>>NoMethodError in Store#empty_cart >>>>>undefined method `empty!'' for #<Cart:0x40be4800> >>>>>/app/controllers/store_controller.rb:28:in `empty_cart'' >>>>>./script/server:49 >>>>> >>>>>and I really don''t understand why ... >>>>> >>>>>Other methods available in cart.rb work well in store_controller ... >>>>> >>>>>Any idea ? >>>> >>>> >>>> >>>>Don''t know why but after a Webrick restart all is working well ... I''m >>>>using development mode, it should automatically reload files that have >>>>changed ... >>>> >>>>See you. >>>> >>>> >>>>------------------------------------------------------------------------ >>>> >>>>_______________________________________________ >>>>Rails mailing list >>>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>>_______________________________________________ >>>Rails mailing list >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >