Friday, August 17, 2012

How to install MongoDB on Ubuntu 11.10

MongoDB can be installed in the following way

then inside /etc/apt/sources.list, append the following line Now add the GPG key and update your package list: Now we can install mongoid db in the following way Now you can check whether mongoDB got installed in a proper way: From your browser also, you can hit the url mentioned below and check whether mongoDB got installed properly.

Sunday, July 15, 2012

Generating Excel file with 'writeexcel' gem & 'axlsx' gem

Well, here I am describing a very short example of creating excel files in ruby. For this example, I have used the gem "writeexcel" writeexcel.

Here is a very small example

Well, Now a small example for generating excel file with axlsx gem.


Sunday, June 17, 2012

Could not find a JavaScript runtime (ExecJS::RuntimeUnavailable)

Hi,  

If you are using 'execjs' gem and if you get the below mentioned error, while starting the application server or executing rake tasks or even starting the console, then you might have to add the gem 'therubyracer'. 

Today, I was getting the following error in my system after installing 'execjs' gem:

/home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could ot find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /home/saurav/.rvm/gems/ruby-1.9.2-p318/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
.......
.......

The solution was to add the following line gem 'therubyracer' to the Gemfile and then execute 

bundle install

Voila !!....I don't see the error any more :) 




Tuesday, May 1, 2012

Referring to class from class method and instance method

Instead of directly writing ClassName for calling methods, this can be done in a different way by writing self.class

Below is a small example: 

Output will be:

Class Name is SomeClass

Class Name is SomeClass

Wednesday, April 25, 2012

Change Column or column type in Rails

Hi, 

If you have to change the column_type of an existing column in a table, you have to create a new migration and do the following changes:

saurav@saurav-Vostro-1540:~/workspace/project$./script/generate migration ChangeNotes

The above command will generate a new migration file and the migration should be like this after you have made the change:

class ChangeNotes < ActiveRecord::Migration
  def self.up
      change_table :notes  do |t|
        t.change :note, :text
       end
    end

    def self.down
      change_table :notes do |t|
        t.change :note, :string
      end
    end
end

where "note" is the column for which I have changed the data-type. Earlier, the data type of "note" column was set to "String" and now it has been set to "text"..

Thursday, February 16, 2012

RVM - No same user error fix

Hi All, 

Today, after installing RVM in my system i was getting a strange error "no same user error" whenever I was trying to install ruby with rvm. I was getting error of similar sort: 
"Error opening archive: Failed to open '--no-same-owner': No such file or directory"
It is actually a bug in rvm, see this commit: 
https://github.com/wayneeseguin/rvm/commit/52018750763d5321b7b993e201c8589b98e090f9 
Finally after some googling, I could solve the issue with the following command:
[administrator@bdsi989-linux administrator]$ rvm get head
Hope this helps some one :)