Friday, November 29, 2013

ruby-1.9.3-p484@pro1/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime

 /home/sachin/.rvm/gems/ruby-1.9.3-p484@pro1/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See for a list of available runtimes. (ExecJS::RuntimeUnavailable)


You can use this for install nodejs package and it will remove this error.

sudo apt-get install nodejs


Inside Gemfile uncomment this or if you have no this then add this gem:

gem 'therubyracer', :platforms => :ruby

undefined local variable or method `version_requirements' in Rails 2.3.5

rake aborted!
undefined local variable or method `version_requirements' for #<Rails::GemDependency:0x7ff44ee9aad0>


Put this code in config/environment.rb between Bootstrap and initializer:

if Gem::VERSION >= "1.3.6"

  module Rails
    class GemDependency
      def requirement
        r = super
        (r == Gem::Requirement.default) ? nil : r

Wednesday, November 27, 2013

uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) with rails 2.3.5


/home/ubuntu64/.rvm/gems/ruby-1.8.7-p374@global/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /home/ubuntu64/.rvm/gems/ruby-1.8.7-p374@global/gems/activesupport-2.3.5/lib/active_support.rb:56
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /home/ubuntu64/.rvm/gems/ruby-1.8.7-p374@global/gems/rails-2.3.5/lib/commands/server.rb:1
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /home/ubuntu64/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'


Add this in top of config/boot.rb:

require 'thread'
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)

Saturday, November 23, 2013

Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)


/home/sachin/.rvm/gems/ruby-1.9.3-p448@rails3/gems/mongo-1.9.2/lib/mongo/mongo_client.rb:486:in `connect': Failed to connect to a master node at localhost:27017 (Mongo::ConnectionFailure)

       sudo rm /var/lib/mongodb/mongod.lock 

For start mongodb:
       sudo start mongodb
       It will give you: mongodb start/running, process 4994

For look at status for mongodb:

       sudo status mongodb 
       It will give you: mongodb start/running, process 4994

Deploy Ruby On Rails Application with Apache server using Phusion Passenger gem

Know about Phusion Passenger:
Phusion Passenger is an application server which can be integrated into web server like Apache and Ngnix web servers.


Ruby (If not then install it)
Rails (If not then do gem install rails -v 3.2.13 )

Follow below steps to deploy:

Step 1: Install Passenger gem
gem install passenger 
Step 2: Install Apache module for Passenger
After completing this command it will provide you code with 3 line for add in your Apache configuration file which is located in 

In my installation Passenger gem's version 4.0.25 is there so it looks like this:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.25/buildout/apache2/
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.25
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby
Step 3: Restart Apache Server
service httpd restart
Step 4 : Set Apache VirtualHost
<VirtualHost *:80>
    DocumentRoot /app-path/public
    <Directory /app-path/public>
        AllowOverride all
        Options -MultiViews
IF you want to check log for debug(error check) with passenger then:

1.) Go inside:
     cd /var/log/httpd
2.) then do it:
     tail -n 300 error_log | more

parse': (): did not find expected key while parsing a block mapping at line 11 column 3 (Psych::SyntaxError)

It was a simple syntax error. I failed to put a space between user: and username. So it threw the same error for both the rake command, and script/about command.

You have invalid YAML code somewhere. I mean invalid for Psych (the new ruby YAML parser).
If you cannot (or don't want to) fix your YAML code, try to load the old YAML parser (syck), adding this at the beginning of config/environment.rb:
require 'yaml'
YAML::ENGINE.yamler = 'syck'

Saturday, November 16, 2013

Can't get CSS working on Production or Heroku using Rails 4

I am using Rails 4. In development environment its working fine but in Production its not loaded.

Run this command:

        RAILS_ENV=production bundle exec rake assets:precompile

Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk.

You can call this task on the server during deployment to create compiled versions of your assets directly on the server.

Rails introduced the Asset Pipeline to concatenate and minify or compress JavaScript and CSS assets. Heroku has a step in the build process to precompile your assets into your slug, so they’re readily available. To speed up asset precompiles, it’s recommended that you tell Rails to only partially load your app. Heroku also, does not provide the whole app environment to the build process, so this is required. In your config/application.rb set the following:

        config.assets.initialize_on_precompile = false
If  you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array in config/application.rb:

         config.assets.precompile += ['zebra.js', 'zebra.css', 'table.js']

And if you want to clean assets then do it:

           rake assets:clean

This command removes compiled assets.