I am new to RoR and trying to learn my way around. I have Bruce Tate''s RoR Up And Running book and am using it to learn RoR. An example in chapter 2 page 34 shows how simple it is to add validation for table records. The example adds validation to the ActiveRecord model class Photo.rb as follows: Class without validation: class Photo < ActiveRecord::Base end Class with validation: class Photo < ActiveRecord::Base validates_presence_of :filename end The MySQL table that this class is managing is as follows: mysql> select * from photos; +----+----------+ | id | filename | +----+----------+ | 1 | Cat.jpg | | 2 | dog.jpg | +----+----------+ 2 rows in set (0.00 sec) Now I am trying to test all this from RoR console as the book is instructing me to. It says to type in the following in the console photo=Photo.new photo.save At this point, the validation is supposed to kick in and I am supposed to get a false reply. Instead I got true and indeed, a new record with empty filename was saved to the photos table. I was wondering as to why the validation did not work until I spotted the text written in the book which said that I will have to restart the console to reload my changes. I did that and the validation started to work. Is there something that I don''t know? I thought that the development environment was supposed to reload your changes instantly. I know that it is true for the Web Server. Why do I have to exit the console and reload it to see my changes? Is there a better way to reload the environment without having to quit the console and having to retype "ruby script/console" and wait for it to reload? Thanks in advance for your reply. bharat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Nathan. As you can tell, I am really new to Rails. Is there a place/book/tutorial where I can find answers for console related questions? I find the console to be very useful tool while learning and would like to know all the commands and tricks like the one you mention above. Regards, Bharat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nathan Leach wrote:> Bharat, > > You can reload a class by typing > > load ''classname.rb'' > > in the console... > > NathanIn development mode all the classes in your app get reloaded on every request. In the console, there is no request, so there is no reload. You can however, simply type: reload! And your models and everything else should get refreshed. -- 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 -~----------~----~----~----~------~----~------~--~---
On Wed, 8 Nov 2006, Bharat wrote:> Now I am trying to test all this from RoR console as the book is > instructing me to. It says to type in the following in the console > photo=Photo.new > photo.save > At this point, the validation is supposed to kick in and I am supposed > to get a false reply. Instead I got true and indeed, a new record with > empty filename was saved to the photos table. I was wondering as to > why the validation did not work until I spotted the text written in the > book which said that I will have to restart the console to reload my > changes. I did that and the validation started to work. > Is there something that I don''t know? I thought that the development > environment was supposed to reload your changes instantly. I know that > it is true for the Web Server. Why do I have to exit the console and > reload it to see my changes? Is there a better way to reload the > environment without having to quit the console and having to retype > "ruby script/console" and wait for it to reload?Think of it this way... when you start console you are in *one* session. Just like if you change a model in the middle of making a request via your browser, it''s not going to update. In other words, every instance of console is a "browser hit". You can type "reload!" and it will reload all the classes. This could invalidate some of your previously find''ed objects though so you might have to re-find them. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bharat, You can reload a class by typing load ''classname.rb'' in the console... Nathan On Wed, 2006-11-08 at 13:20 -0800, Bharat wrote:> I am new to RoR and trying to learn my way around. I have Bruce Tate''s > RoR Up And Running book and am using it to learn RoR. > An example in chapter 2 page 34 shows how simple it is to add > validation for table records. The example adds validation to the > ActiveRecord model class Photo.rb as follows: > > Class without validation: > class Photo < ActiveRecord::Base > end > > Class with validation: > class Photo < ActiveRecord::Base > validates_presence_of :filename > end > > The MySQL table that this class is managing is as follows: > > mysql> select * from photos; > +----+----------+ > | id | filename | > +----+----------+ > | 1 | Cat.jpg | > | 2 | dog.jpg | > +----+----------+ > 2 rows in set (0.00 sec) > > Now I am trying to test all this from RoR console as the book is > instructing me to. It says to type in the following in the console > photo=Photo.new > photo.save > At this point, the validation is supposed to kick in and I am supposed > to get a false reply. Instead I got true and indeed, a new record with > empty filename was saved to the photos table. I was wondering as to > why the validation did not work until I spotted the text written in the > book which said that I will have to restart the console to reload my > changes. I did that and the validation started to work. > Is there something that I don''t know? I thought that the development > environment was supposed to reload your changes instantly. I know that > it is true for the Web Server. Why do I have to exit the console and > reload it to see my changes? Is there a better way to reload the > environment without having to quit the console and having to retype > "ruby script/console" and wait for it to reload? > Thanks in advance for your reply. > bharat > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks you all gentlemen for your helpful comments. I am going to enjoy being a part of RoR community. Regards, Bharat --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nathan Leach wrote:> Bharat, > > You can reload a class by typing > > load ''classname.rb'' > > in the console... > > Nathan-- 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 -~----------~----~----~----~------~----~------~--~---