The console is an extremely useful tool for development and debugging. To start it up, move to your application’s home directory and:
script/console
After a short pause, you’ll get an irb-like console prompt. At this point, you can reference your application’s objects, edit them, change them and so on.
For example, from the >>> prompt:| Post.find(1) | this shows you the first record in the ‘posts’ table |
| p = Post.find(1) | this creates an object p and points it to the first record in the ‘posts’ table |
| p.updated_at | this will show the value of the ‘updated_at’ field in the record pointed to by object p |
and so on.
Remember, if you change the code in your models it will not be reflected in the console as all models have already been loaded into memory. Good news is you don’t have to restart the console simply enter
reload! at the prompt.This is the best way I’ve found of being able to quickly test some code to ensure I know what it does, prior to putting it into my application.
More excellent information is available
here
You can also use the console for examining helper methods. For instance:
C:\rails_apps\my_app> ruby script/console Loading development environment. >> helper => #<Object:0x486fdb8> >> helper.number_to_currency(234) => "$234.00" >>
The console is an extremely useful tool for development and debugging. To start it up, move to your application’s home directory and:
script/console
After a short pause, you’ll get an irb-like console prompt. At this point, you can reference your application’s objects, edit them, change them and so on.
For example, from the >>> prompt:| Post.find(1) | this shows you the first record in the ‘posts’ table |
| p = Post.find(1) | this creates an object p and points it to the first record in the ‘posts’ table |
| p.updated_at | this will show the value of the ‘updated_at’ field in the record pointed to by object p |
and so on.
Remember, if you change the code in your models it will not be reflected in the console as all models have already been loaded into memory. Good news is you don’t have to restart the console simply enter
reload! at the prompt.This is the best way I’ve found of being able to quickly test some code to ensure I know what it does, prior to putting it into my application.
More excellent information is available
here
You can also use the console for examining helper methods. For instance:
C:\rails_apps\my_app> ruby script/console Loading development environment. >> helper => #<Object:0x486fdb8> >> helper.number_to_currency(234) => "$234.00" >>