Monday, August 22, 2011

ActiveRecord callback execution sequence..

 Given below are the sequence of executions of
ActiveRecord callbacks.
Its handy when you have to execute particular piece of code at
particular time of record creation.
 
For before_persisting callback 
 before_persisting
  persist
  after_persisting
  [save record if record.changed?]
  
For befor_validation callback
  before_validation
  before_validation_on_create
  before_validation_on_update
validate
  after_validation_on_update
  after_validation_on_create
  after_validation
  [save record if record.changed?]
 
For before_create and before_update callback
before_save
before_create
before_update
saves the record
after_update
after_create
after_save
  [save record if record.changed?]
  
For before_destory callback
  before_destroy
  [save record if record.changed?]
  destroy
  after_destroy

Saturday, August 20, 2011

error: no such file to load — readline 

The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. (…) The Readline library includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous command.

For more info about read line visit http://bogojoker.com/readline/

When I started  rails console: I got an error saying:
no such file to load — readline (LoadError).  At that time i was on Ubuntu 10.04 system with rvm, rails3, ruby 1.9.2-p290.
I tracked down redline in my ruby source ~/.rvm/src/ruby-1.9.2-p290/ext/readline and ran:
ruby extconf.rb
(Note: here ruby-1.9.2-p290 is the default ruby in rvm. Replace with your ruby version if you have to.)
This let me know I was missing these two packages:
libncurses5-dev and libreadline5-dev
Install these packages with this command

sudo apt-get install libncurses5-dev libreadline5-dev
Then run the command from before:
ruby extconf.rb
Note :
You should be in the  ~/.rvm/src/ruby-1.9.2-p290/ext/readline
directory while entering this command.
I think you should get all passing.
make
make install
Hurray now rails c works.

Friday, August 19, 2011

Install Rails in Ubuntu with RVM

Before installing rvm first of all you need to install a latest version of git in your system.
Run this command in the terminal
sudo aptitude build-dep git-core
Then run the command 
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
to install rvm in your machine.
Now run the command
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" 
# Load RVM function' >> ~/.bash_profile

To load RVM into your shell sessions as a function.

Now reload the bash with

source .bash_profile
If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output 'rvm is a function' as shown below.  
type rvm | head -1

 Now install ruby with rvm with this comand
rvm install 1.9.2-p290
where 1.9.2-p290 is ruby version that we want to install.


now make ruby 1.9.2 your default ruby for the system with this command
rvm use 1.9.2 --default
Now install rails with 
gem install rails --no-ri --no-rdoc
if you get the following error

ERROR:  Loading command: install (LoadError)
    no such file to load -- zlib
ERROR:  While executing gem ... (NameError)
    uninitialized constant Gem::Commands::InstallCommand

then you must install zlib package. Use the following commands if above error shows up


$ rvm pkg install zlib
$ rvm remove 1.9.2
$ rvm install 1.9.2 --with-zlib-dir=$rvm_path/usr


here --no-ri --no-rdoc  will not install ri and rdoc documentation.