1. installing ruby-debug with ruby 1.9.x says …Can’t handle 1.9.x yet…

    Today I was trying to install ruby-debug gem under ruby version ruby-1.9.2-p290 I got the following error

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

            /home/sameera/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
    Can’t handle 1.9.x yet
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

    Provided configuration options:
        —with-opt-dir
        —without-opt-dir
        —with-opt-include
        —without-opt-include=${opt-dir}/include
        —with-opt-lib
        —without-opt-lib=${opt-dir}/lib
        —with-make-prog
        —without-make-prog
        —srcdir=.
        —curdir
        —ruby=/home/sameera/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

    so it appears to be that, ruby-debug is not compatible with ruby 1.9.x, So after some gooling I found a simple solution its the ‘debugger’ (https://github.com/cldwalker/debugger), So simply in your Gemfile add the following line

    gem ‘debugger’

    instead of

    gem ‘ruby-debug’

    :)

  2. Fixing,.. bundle: command not found error

    When you are working with rails/ bundler you might have had this error message

    bundle: command not found

    But, you are pretty sure that bundler is installed in your machine… So what would be the reason !?, Ok, you may already have the answer, the answer is even though you have bundler installed, its not in your system PATH

    So how to add bundler to your system path, heres how

    1 - First you have to see find the ruby gem executable path to your path directory,

    to do this run the following command

    gem environment

    Ex:  (here is mine)

    RubyGems Environment:

      - RUBYGEMS VERSION: 1.7.2

      - RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]

      - INSTALLATION DIRECTORY: /home/sameera/.rvm/gems/ruby-1.8.7-p357

      - RUBY EXECUTABLE: /home/sameera/.rvm/rubies/ruby-1.8.7-p357/bin/ruby

      - EXECUTABLE DIRECTORY: /home/sameera/.rvm/gems/ruby-1.8.7-p357/bin

      - RUBYGEMS PLATFORMS:

        - ruby

        - x86_64-linux

      - GEM PATHS:

         - /home/sameera/.rvm/gems/ruby-1.8.7-p357

         - /home/sameera/.rvm/gems/ruby-1.8.7-p357@global

      - GEM CONFIGURATION:

         - :update_sources => true

         - :verbose => true

         - :benchmark => false

         - :backtrace => false

         - :bulk_threshold => 1000

      - REMOTE SOURCES:

         - http://rubygems.org/

    So here is the executable path
    EXECUTABLE DIRECTORY: /home/sameera/.rvm/gems/ruby-1.8.7-p357/bin

    2 - Then add this path to your $PATH variable

    here is how
    export PATH=$PATH:<ruby gem executable path>
    Ex: export PATH=$PATH:/home/sameera/.rvm/gems/ruby-1.8.7-p357/bin
    that’s it, So now your system knows how to run bundler 
    try bundle , (and it should work :D)

  3. Upgrading ruby gems on ubuntu linux

    If you are on Linux(Ubuntu 10.04) or later and try to upgrade your ruby gems you will most probably getting the following warning

    gem update —system

    "ERROR:  gem update —system is disabled on Debian, because it will overwrite the content of the rubygems Debian package, and might break your Debian system in subtle ways. The Debian-supported way to update rubygems is through apt-get, using Debian official repositories.

    If you really know what you are doing, you can still update rubygems by setting the REALLY_GEM_UPDATE_SYSTEM environment variable, but please remember that this is completely unsupported by Debian. “

    So here is my current gem environment

    RubyGems Environment:

      - RUBYGEMS VERSION: 1.7.2

      - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]

    So fixing/work around this issue is not that hard, after some goggling I found the working solution

    Solution

    first install 'rubygems-update' gem

    sudo gem install rubygems-update

    And then run the command

    sudo update_rubygems

    And this is my new gem env

    RubyGems Environment:

      - RUBYGEMS VERSION: 1.8.11


    Thats it, :D


  4. Using RVM to Keep Things Simple

    When you working with Rails/Ruby sooner or later you will have a situation where  you need to have multiple rails projects with different rails / ruby versions

    Things get more complicated when you need to keep more than one ruby version in your computer like

    • ruby-1.8.7
    • ruby 1.9.2

    Coz if you are to work with rails 3 or above its often a recommended practice to go with ruby-1.9.2 

    Having several different gem versions makes your life a nightmare, specially when you execute commands like rake

    So what is the solution to have different ruby/rails versions, answer is RVM (Ruby Version Manager), And I believe all of you may have already heard lots of good about it.

    Yeah it is a cool tool, And I was using it ..ah… actually blindly until very recently I figure out how useful is GemSet concept in RVM

    So this post is entirely based on how you could create a gem set and how to use it, OK lets start…

    Lets say I have two rails projects

    1. A - using ruby1.8.7 and rails 2.3.8
    2. B - using ruby1.9.2 and rails 3.0

    So lets install ruby1.8.7

    in your command prompt execute

    rvm install 1.8.7
    Then create a GemSet - gemset is nothing but just a name which you could group your ruby  version and related gems
    Lets name our gem set rails2

    execute this command to create your gem set

    rvm gemset create rails2

    Ok now we can install rails which will be grouped under this GemSet, But before that we have to make this as default

    rvm use 1.8.7@rails2 —default

    Easy enough right, So lets install rails 2.3.8, and its nothing fancy

    gem install rails -v 2.3.8

    Ok done, now we will repeat the same process to ruby1.9.2
    rvm install 1.8.7

    I will create this gemset as rails3

    rvm gemset create rails3

    Now to install rails3 make the rails3 gemset as default

    rvm use 1.9.2@rails3 —default

    Then install rails

          gem install rails -v 3.0.0

    Done…

    so now running the projects is simple as, when you want  to run the project A, activate the rails2 gem set,

    rvm use 1.8.7@rails2 —default

    And when you want to run project B, simply activate rails3 gemset

    rvm use 1.9.2@rails3 —default

    ……

    This post is inspired by the following post, its worth reading it

    http://stjhimy.com/posts/10-five-quick-steps-to-set-up-rvm-with-rails-2-and-rails3

  5. installing mysql with rails —— in linux with bundler

    Most of the rails developers use mysql as their backend, so do I. Few days back I got a fresh machine to install ruby / rails.

    While I’m pretty impressive with bundler installation (bundler was able to install all my gems smoothly), It had a problem with mysql gem.Following is the error I got

    Installing mysql (2.8.1) with native extensions /usr/lib/ruby/1.8/rubygems/installer.rb:483:in `build_extensions’: ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

    /usr/bin/ruby1.8 extconf.rb
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lm… yes
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lz… yes
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lsocket… no
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lnsl… yes
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lmygcc… no
    checking for mysql_query() in -lmysqlclient… no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

    Provided configuration options:
        —with-opt-dir
        —without-opt-dir
        —with-opt-include
        —without-opt-include=${opt-dir}/include
        —with-opt-lib
        —without-opt-lib=${opt-dir}/lib
        —with-make-prog
        —without-make-prog
        —srcdir=.
        —curdir
        —ruby=/usr/bin/ruby1.8
        —with-mysql-config
        —without-mysql-config
        —with-mysql-dir
        —without-mysql-dir
        —with-mysql-include
        —without-mysql-include=${mysql-dir}/include
        —with-mysql-lib
        —without-mysql-lib=${mysql-dir}/lib
        —with-mysqlclientlib
        —without-mysqlclientlib
        —with-mlib
        —without-mlib
        —with-mysqlclientlib
        —without-mysqlclientlib
        —with-zlib
        —without-zlib
        —with-mysqlclientlib
        —without-mysqlclientlib
        —with-socketlib
        —without-socketlib
        —with-mysqlclientlib
        —without-mysqlclientlib
        —with-nsllib
        —without-nsllib
        —with-mysqlclientlib
        —without-mysqlclientlib
        —with-mygcclib
        —without-mygcclib
        —with-mysqlclientlib
        —without-mysqlclientlib

    This be basically because when I’m installing mysql on my linux box, i missed some header files. to install them I need to install mysql-dev packages, its not hard

    just go to synaptic package manager, select following files to be install

    libmysqlclient-dev
    libmysqlclient16

    thats it.. now go to bundler

    sudo bundle install

    should work perfectly

    credit goes to

    http://stackoverflow.com/questions/3754662/errors-installing-mysql2-gem-via-the-bundler

  6. setup a rails project in breeze - rails_wizard

    rails_wizard is a gem which you can find here or use it as a hosted app from here which will allow developers to select the modules that he/she wants to integrate with the rails app.

    Ex: I might want to create and app with following modules / architecture

    Authentication

    • device

    Presentation Layer

    • LESS
    • HAML
    • JQuery

    ORM

    • ActiveRecord (default orm mapper)

    Testing

    • RSpec
    • Capybara

    So in a case like this,  its actually a pain in the a** to configure all these gems to run side by side

    But thanks to rails_wizard , all you need to do is select the modules you want, and it will give you an URL which you can paste on your console. 

    Ex: 

    rails new APP_NAME http://railswizard.org/a804c35fd478e28faa3e.rb

    Thats is, really thats it…. a new rails app will be created with all the modules you have been requested

    Its really..cooool..


  7. Require ActiveRecord gem , Gem Gotcha

    You might have come across with situations where you want to require rubygems specially activerecord in your .rb files (outside rails)

    possible such code will look like this

    require ‘rubygems’

    require ‘activerecord’

    But…. unfortunately you will end up with following error

    <internal:lib/rubygems/custom_require>:29:in `require’: no such file to load — activerecord (LoadError)

    coz, even though your 

    gem list  command will give you active record gem name as ‘activerecord’, the way you should require active record is as follows

    require ‘rubygems’

    require ‘active_record’

    NOTE : the “_” between active and record (active_record)

    Thats it…. :D



  8. I moved to tumblr

    I used to blogged on wordpress (ok.. to be frank.. I’m not a frequent blogger..). So the reason of moving to tumblr is that I find it simple… Its damn simple…

    In case if you are interested in my previous posts have a look at them here ..