Ruby on Rails

ExecJS::RuntimeError on Windows on Rails 3.1 and above

On the system having issues, find ExecJS’s runtimes.rb file which will present in execjs gem. Make a copy of the found file for backup. Open the original runtimes.rb for editing. Find the section that starts with the line JScript = ExternalRuntime.new( // other Options ) and replaced it with JScript = ExternalRuntime.new( :name => “JScript”, :command => […]

Simple Metaprogram to Dynamically inject Class Methods and Instance Methods from module

module DummyModule module ClassMethods def find_by_ranks() puts “Class Method Executed Successfully !!!” end end module InstanceMethods def ranks() puts “instance method Executed Successfully !!!” end end def self.included(base) base.send :include, InstanceMethods base.send :extend, ClassMethods end end class Test include DummyModule end t = Test.new t.ranks #output : instance method Executed Successfully !!! Test.find_by_ranks #output : […]

Create a new Rails App Using Specific Version

As we now Rails Community is a very active commnity and Number of rails version are get released so here is a  short command I found to create a rails application by using Specific version $ rails _3.2.13_ new appname

Capistrano Deployment Using Local SSH key

Here is the steps to deploy the Application using SSH keys without Password $ ssh-copy-id user@remote-host Then you can login to Remote Host using  command without password as : $ ssh user@remote-host After this done open the deploy.rb of your Application file and add the following line in your deploy.rb set :user, ‘amit’ set :ssh_options, […]

Getting Invalid encoding UTF-8 and ASCII-8BIT error while parsing CSV. in Ruby

Once I parsing a CSV file. it will work for ruby1.8 but it give me encoding error while parsing same file using ruby1.9.   The following error is soled by just added this line to the string “Errored string”.force_encoding(“ISO-8859-1”).encode(“utf-8”, replace: nil) 🙂  

Error while installing Rmagick gem

You get an error while installing rmagick gem due to its dependency  i.e. imagemagick libraries not installed properly in ubuntu we can install the imagemagick by following command apt-get install imagemagick librmagick-ruby libmagickwand-dev

Access Rails Helpers in Mailers view.

we can access Helper from Rails in mailers view by simply “add_template_helper(ApplicationHelper)” in a mailer in given way below class NotificationsMailer < ActionMailer::Base add_template_helper(ApplicationHelper) end

Installing mysql2 gem on Windows using xampp

Earlier while installing gem i got the error that it not find the nysql libraries. then i resolved it and install the mysql gem by following command gem install mysql2 –version=0.2.7 — –with-mysql-lib=”c:\xampp\mysql\lib” –with-mysql-include=”c:\xampp\mysql\include”

Change or Share DATABASE_URL in Heroku App.

Simply set the DATABASE_URL config var for several apps to the same value. First, get the DATABASE_URL for your existing app by command $ heroku config | grep DATABASE_URL the you can set the url for your database for your Heroku app as $ heroku config:add DATABASE_URL = “Your Database Url”

Capistrano Could not parse object ‘e8c10038180509bc602afef37b5d1a02576e3810’.

The easy solution for above problem is just to go to the server to which you are attempting to deploy and delete the “cached-copy” directory under the “shared” directory. You should be good now.