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