Tuesday, September 23, 2008

Rails Console Tips & Tricks II

This is my second rails console tips & tricks. if you interested in reading previous tips and tricks read my first blog post regarding that matter.

This second part is about one command called "load" that is available in your Rails console. you can use this command to do many things as

1. to reload any file that was loaded when starting console and don't get reloaded when using "reload!" command such as files in your lib folder. to reload any file just write

load "#{RAILS_ROOT}/lib/{{file_name}}"


2. if you faced a problem such as "MySQL has gone away" just reload environment.rb once again as follows

load "#{RAILS_ROOT}/config/environment.rb"


3. also if you want to test a bunch of code in your console not just a single line of code, and want to be able to change part in it and rerun it once again then doing so in console is very time consuming and annoying so rather than doing so, you can write this code in a file and then

load "{{your-ruby-file}}"

No comments: