Friday, May 27, 2011

Thinking Sphinx giving error "Failed to start searchd daemon"

I have Rails 3.0 application running on Windows 7. I am using Thinking Sphinx. I configured it and worked for few days. One day, after some file update when I ran "rake ts:start", it gives following errors:

C:\projects\demo>rake ts:start
(in C:/projects/demo)

Sphinx cannot be found on your system. You may need to configure the following
settings in your config/sphinx.yml file:
  * bin_path
  * searchd_binary_name
  * indexer_binary_name

For more information, read the documentation:
http://freelancing-god.github.com/ts/en/advanced_config.html
C:/Ruby187/bin/rake: No such file or directory - searchd --pidfile --config "C:/projects/demo/config/development.sphinx.conf"
Failed to start searchd daemon. Check C:/projects/demo/log/searchd.log.
Failed to start searchd daemon. Check C:/projects/demo/log/searchd.log

When I checked 'searchd.log' file it displays following error:
[Wed Apr 27 19:28:50.187 2011] [  236] accepting connections
[Wed Apr 27 19:35:05.546 2011] [  236] caught SIGTERM, shutting down
[Wed Apr 27 19:35:05.630 2011] [  236] shutdown complete

Steps to fix the error:

Change the 'config/sphinx.yml' file and give path to bin directory where Sphinx is installed as given below:
development:
  bin_path: "C:/Sphinx/bin"

Then run
rake thinking_sphinx:index
rake thinking_sphinx:start
and it will run without any error.

Wednesday, May 25, 2011

RailsConf 2011: David Heinemeier Hansson





Complete live blog with DHH's keynotes is blogged on
http://www.rubyinside.com/dhh-keynote-streaming-live-from-railsconf-2011-right-here-right-now-4769.html

Could not find gem 'sass (>= 0)' in any of the gem sources listed in your Gemfile

Ruby version - ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
I ran the command 'gem install rails --pre' to install 'Rails 3.1.0.beta1'.

When checking 'rails -v', it gives following errors:
Could not find gem 'sass (>= 0)' in any of the gem sources listed in your Gemfile

Steps to fix the error:
Fixed the error by running the command 'gem install sass' separately.

And then again I checked rails version, it gave:
Rails 3.1.0.beta1

Tuesday, May 24, 2011

'rake ts:rebuild' giving 'execution expired' error

I have one Rails 3.0 application on linux. I am using Thinking Sphinx.
When I ran rake ts:rebuild, I got following error:

rake ts:rebuild
(in /var/www/rails/sphinx/releases/20110524133955)
d. Use lib/tasks instead. (called from /var/www/rails/sphinx/releases/20110524133955/Rakefile:7)
** Invoke ts:restart (first_time)
** Invoke thinking_sphinx:restart (first_time)
** Invoke thinking_sphinx:app_env (first_time)
** Execute thinking_sphinx:app_env
** Invoke thinking_sphinx:stop (first_time)
** Invoke thinking_sphinx:app_env
** Execute thinking_sphinx:stop
rake aborted!
execution expired
/usr/lib/ruby/1.8/timeout.rb:60
/home/advent-ror/.bundler/ruby/1.8/thinking-sphinx-3fbd0df76796/lib/thinking_sphinx/tasks.rb:53
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

Steps to fix the error:
This error occurs when search daemon is already running, so first we have to kill the search daemon process.
To find out the process ID, run the command
ps | grep searchd
OR
pgrep searchd
It will give you a process ID.

Kill the process by command
"sudo kill -9 process_id", change the process_id with yours one.

Then run rake ts:rebuild again.

Friday, May 20, 2011

'gem install rails --pre' command break while installing 'Rails 3.1 beta 1'

'gem install rails --pre' command break while installing  'Rails 3.1 beta 1'  with Ruby 1.8.7 but installed successfully with Ruby 1.9.2

I am trying to install 'Rails 3.1 beta 1' on Windows 7. I have already installed Ruby two versions -  'ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]' and 'ruby 1.9.2p180 (2011-02-18) [i386-mingw32]' and handling them with pik.

When I ran command 'gem install rails --pre' on Ruby 1.8.7, installation break with following errors:
C:\Users\ritesh>ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]


C:\Users\ritesh>gem install rails --pre
Successfully installed multi_json-1.0.2
Successfully installed activesupport-3.1.0.beta1
Successfully installed builder-3.0.0
Successfully installed i18n-0.6.0beta1
Successfully installed activemodel-3.1.0.beta1
Successfully installed rack-1.3.0.beta2
Successfully installed rack-cache-1.0.2
Successfully installed rack-test-0.6.0
Successfully installed rack-mount-0.7.4
Successfully installed hike-1.0.0
Successfully installed tilt-1.3
Successfully installed sprockets-2.0.0.beta.5
Successfully installed erubis-2.7.0
Successfully installed actionpack-3.1.0.beta1
Successfully installed arel-2.1.1
Successfully installed activerecord-3.1.0.beta1
Successfully installed activeresource-3.1.0.beta1
Successfully installed mail-2.3.0
Successfully installed actionmailer-3.1.0.beta1
Successfully installed rack-ssl-1.3.2
Successfully installed railties-3.1.0.beta1
Successfully installed rails-3.1.0.beta1
22 gems installed
Installing ri documentation for multi_json-1.0.2...
Building YARD (yri) index for multi_json-1.0.2...
Installing ri documentation for activesupport-3.1.0.beta1...
Building YARD (yri) index for activesupport-3.1.0.beta1...
Installing ri documentation for builder-3.0.0...
ERROR:  While generating documentation for builder-3.0.0
... MESSAGE:   Unhandled special: Special: type=17, text="<!-- HI -->"
... RDOC args: --ri --op C:/Ruby187/lib/ruby/gems/1.8/doc/builder-3.0.0/ri --title Builder -- Easy XML Building --main README.rdoc --line-numbers --quiet lib CHANGES Rakefile README README.rdoc TAGS doc/releases/builder-1.2.4.rdoc
 doc/releases/builder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc --title builder-3.0.0 Documentation
(continuing with the rest of the installation)
Building YARD (yri) index for builder-3.0.0...
Installing ri documentation for i18n-0.6.0beta1...
Building YARD (yri) index for i18n-0.6.0beta1...
Installing ri documentation for activemodel-3.1.0.beta1...
Building YARD (yri) index for activemodel-3.1.0.beta1...
Installing ri documentation for rack-1.3.0.beta2...
Building YARD (yri) index for rack-1.3.0.beta2...
Installing ri documentation for rack-cache-1.0.2...
Building YARD (yri) index for rack-cache-1.0.2...
Installing ri documentation for rack-test-0.6.0...
Building YARD (yri) index for rack-test-0.6.0...
Installing ri documentation for rack-mount-0.7.4...
Building YARD (yri) index for rack-mount-0.7.4...
Installing ri documentation for hike-1.0.0...
Building YARD (yri) index for hike-1.0.0...
Installing ri documentation for tilt-1.3...
Building YARD (yri) index for tilt-1.3...
Installing ri documentation for sprockets-2.0.0.beta.5...
Building YARD (yri) index for sprockets-2.0.0.beta.5...
Installing ri documentation for erubis-2.7.0...
Building YARD (yri) index for erubis-2.7.0...
Installing ri documentation for actionpack-3.1.0.beta1...
Building YARD (yri) index for actionpack-3.1.0.beta1...
Building YARD (yri) index for arel-2.1.1...
Installing ri documentation for activerecord-3.1.0.beta1...
Building YARD (yri) index for activerecord-3.1.0.beta1...
Installing ri documentation for activeresource-3.1.0.beta1...
Building YARD (yri) index for activeresource-3.1.0.beta1...
Installing ri documentation for mail-2.3.0...
Building YARD (yri) index for mail-2.3.0...
Installing ri documentation for actionmailer-3.1.0.beta1...
Building YARD (yri) index for actionmailer-3.1.0.beta1...
Installing ri documentation for rack-ssl-1.3.2...
Building YARD (yri) index for rack-ssl-1.3.2...
Installing ri documentation for railties-3.1.0.beta1...
Building YARD (yri) index for railties-3.1.0.beta1...
[error]: Unhandled exception in YARD::Handlers::Ruby::Legacy::ModuleHandler:
[error]:   in `lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb`:1:

         1: module <%= camelized %>

[error]: ArgumentError: invalid empty object name
[error]: Stack trace:
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/code_objects/base.rb:167:in `new'
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/handlers/ruby/legacy/module_handler.rb:7:in `process'
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/handlers/processor.rb:90:in `process'
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/handlers/processor.rb:88:in `each'
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/handlers/processor.rb:88:in `process'
        C:/Ruby187/lib/ruby/gems/1.8/gems/yard-0.6.3/lib/yard/handlers/ruby/legacy/class_handler.rb:54:in `each_with_index'

Installing ri documentation for rails-3.1.0.beta1...
File not found: lib


Then I switched to Ruby 1.9.2 and tried 'gem install rails --pre' again, and it installed successfully.
C:\Users\ritesh>ruby -v
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]

 
C:\Users\ritesh>gem install rails --pre
Fetching: multi_json-1.0.2.gem (100%)
Fetching: activesupport-3.1.0.beta1.gem (100%)
Fetching: builder-3.0.0.gem (100%)
Fetching: i18n-0.6.0beta1.gem (100%)
Fetching: bcrypt-ruby-2.1.4-x86-mingw32.gem (100%)
Fetching: activemodel-3.1.0.beta1.gem (100%)
Fetching: rack-1.3.0.beta2.gem (100%)
Fetching: rack-cache-1.0.2.gem (100%)
Fetching: rack-test-0.6.0.gem (100%)
Fetching: rack-mount-0.7.4.gem (100%)
Fetching: hike-1.0.0.gem (100%)
Fetching: tilt-1.3.gem (100%)
Fetching: sprockets-2.0.0.beta.5.gem (100%)
Fetching: tzinfo-0.3.27.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.1.0.beta1.gem (100%)
Fetching: arel-2.1.1.gem (100%)
Fetching: activerecord-3.1.0.beta1.gem (100%)
Fetching: activeresource-3.1.0.beta1.gem (100%)
Fetching: mail-2.3.0.gem (100%)
Fetching: actionmailer-3.1.0.beta1.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: railties-3.1.0.beta1.gem (100%)
Fetching: rails-3.1.0.beta1.gem (100%)
Successfully installed multi_json-1.0.2
Successfully installed activesupport-3.1.0.beta1
Successfully installed builder-3.0.0
Successfully installed i18n-0.6.0beta1
Successfully installed bcrypt-ruby-2.1.4-x86-mingw32
Successfully installed activemodel-3.1.0.beta1
Successfully installed rack-1.3.0.beta2
Successfully installed rack-cache-1.0.2
Successfully installed rack-test-0.6.0
Successfully installed rack-mount-0.7.4
Successfully installed hike-1.0.0
Successfully installed tilt-1.3
Successfully installed sprockets-2.0.0.beta.5
Successfully installed tzinfo-0.3.27
Successfully installed erubis-2.7.0
Successfully installed actionpack-3.1.0.beta1
Successfully installed arel-2.1.1
Successfully installed activerecord-3.1.0.beta1
Successfully installed activeresource-3.1.0.beta1
Successfully installed mail-2.3.0
Successfully installed actionmailer-3.1.0.beta1
Successfully installed rack-ssl-1.3.2
Successfully installed railties-3.1.0.beta1
Successfully installed rails-3.1.0.beta1
24 gems installed
Installing ri documentation for multi_json-1.0.2...
Installing ri documentation for activesupport-3.1.0.beta1...
Installing ri documentation for builder-3.0.0...
Installing ri documentation for i18n-0.6.0beta1...
Installing ri documentation for bcrypt-ruby-2.1.4-x86-mingw32...
Installing ri documentation for activemodel-3.1.0.beta1...
Installing ri documentation for rack-1.3.0.beta2...
Installing ri documentation for rack-cache-1.0.2...
Installing ri documentation for rack-test-0.6.0...
Installing ri documentation for rack-mount-0.7.4...
Installing ri documentation for hike-1.0.0...
Installing ri documentation for tilt-1.3...
Installing ri documentation for sprockets-2.0.0.beta.5...
Installing ri documentation for tzinfo-0.3.27...
Installing ri documentation for erubis-2.7.0...
Installing ri documentation for actionpack-3.1.0.beta1...
Installing ri documentation for arel-2.1.1...
Installing ri documentation for activerecord-3.1.0.beta1...
Installing ri documentation for activeresource-3.1.0.beta1...
Installing ri documentation for mail-2.3.0...
Installing ri documentation for actionmailer-3.1.0.beta1...
Installing ri documentation for rack-ssl-1.3.2...
Installing ri documentation for railties-3.1.0.beta1...
Installing ri documentation for rails-3.1.0.beta1...
Installing RDoc documentation for multi_json-1.0.2...
Installing RDoc documentation for activesupport-3.1.0.beta1...
ERROR:  While generating documentation for activesupport-3.1.0.beta1
... MESSAGE:   incompatible character encodings: UTF-8 and ASCII-8BIT
... RDOC args: lib
(continuing with the rest of the installation)
Installing RDoc documentation for builder-3.0.0...
Installing RDoc documentation for i18n-0.6.0beta1...
Installing RDoc documentation for bcrypt-ruby-2.1.4-x86-mingw32...
Installing RDoc documentation for activemodel-3.1.0.beta1...
Installing RDoc documentation for rack-1.3.0.beta2...
Installing RDoc documentation for rack-cache-1.0.2...
Installing RDoc documentation for rack-test-0.6.0...
Installing RDoc documentation for rack-mount-0.7.4...
Installing RDoc documentation for hike-1.0.0...
Installing RDoc documentation for tilt-1.3...
Installing RDoc documentation for sprockets-2.0.0.beta.5...
Installing RDoc documentation for tzinfo-0.3.27...
Installing RDoc documentation for erubis-2.7.0...
Installing RDoc documentation for actionpack-3.1.0.beta1...
Installing RDoc documentation for arel-2.1.1...
Installing RDoc documentation for activerecord-3.1.0.beta1...
Installing RDoc documentation for activeresource-3.1.0.beta1...
Installing RDoc documentation for mail-2.3.0...
Installing RDoc documentation for actionmailer-3.1.0.beta1...
Installing RDoc documentation for rack-ssl-1.3.2...
Installing RDoc documentation for railties-3.1.0.beta1...
Installing RDoc documentation for rails-3.1.0.beta1...

C:\Users\ritesh>




I observed some difference when installing with Ruby 1.8.7 and Ruby 1.9.2.

No.1 : When I tried to install 'Rails 3.1 beta 1' with Ruby 1.8.7, installation breaks, but with Ruby 1.9.2 it completes the installation with success.
No.2 : With Ruby 1.8.7 it installed 22 gems and with Ruby 1.9.2 it installed 24 gems
No. 3 :  Its building YARD (yri) index after Installing ri documentation in Ruby 1.8.7, but no such YARD index on Ruby 1.9.2.

Wednesday, May 18, 2011

Rails 3.1 Beta: Links, Resources, Tutorials, Tips, References to start with Rails3.1

Rails 3.1 Guide :
http://ryanbigg.com/guides/initialization.html

RailsConf 2011 Live Stream Video:
http://en.oreilly.com/rails2011/public/content/video

Rails 3.1 Feature: Automatic Flushing, Streaming
http://yehudakatz.com/2010/09/07/automatic-flushing-the-rails-3-1-plan/ 
https://github.com/oggy/template_streaming
http://weblog.rubyonrails.org/2011/4/18/why-http-streaming

Rails 3.1 Overview& Features
http://asciicasts.com/episodes/265-rails-3-1-overview
http://hemju.com/2011/02/23/rails-3-1-release-rumors-and-news-about-features/
http://www.hagenburger.net/TALKS/rails-3.1-frontend-performance.html#slide27

Rails 3.1 Feature: Reversible Migration:
http://edgerails.info/articles/what-s-new-in-edge-rails/2011/05/06/reversible-migrations/index.html


Rails 3.1 Features: SASS, Coffee Script, Sprockets
http://www.rubyinside.com/rails-3-1-adopts-coffeescript-jquery-sass-and-controversy-4669.html
http://www.victusspiritus.com/2011/05/11/the-four-horsemen-of-rails-3-1beta-coffee-script-jquery-scss-and-assets/
http://www.rubyinside.com/how-to-rails-3-1-coffeescript-howto-4695.html

Rails 3.1 Features: Coffee Script, Sprockets
http://teachmetocode.com/screencasts/rails-3-1-beta-sprockets-coffeescript-and-jquery-a-teach-me-to-code-tutorial/
http://jackdempsey.me/2011/04/22/rails-3-1-sprockets-and-coffeescript.html

 Rails 3.1 Features: JQuery
http://techoctave.com/c7/posts/49-rails-3-1-and-the-jquery-effect

Rails 3.1 Features: Sproutcore
http://thechangelog.com/post/2155333557/episode-0-4-2-rails-3-1-and-sproutcore-with-yehuda-katz

Rails 3.1 Features: ActiveRecord Identity Map
http://edgerails.info/articles/what-s-new-in-edge-rails/2011/04/21/activerecord-identity-map/index.html

Rails 3.1 Features: ActiveModel ::SecurePassword
http://bcardarella.com/post/4668842452/exploring-rails-3-1-activemodel-securepassword

Monday, May 9, 2011

Rails 3.1 beta 1 released on 05th May, 2011

First sight of Rails 3.1 is here, its first release as 'Rails 3.1 beta 1' on 5th May, 2011.

You can install the gem with command:

gem install rails --pre

and its tag can be found on 3.1.0.beta1.

Its not yet complete but close to complete with few documentation which will soon be coming full-fledge in the next few weeks. So stay tuned.

I am very excited about Rails 3.1 release.

Simple Ruby Scraping Script and storing the result in database

In my previous post Simple Ruby Screen Scraper using Mechanize, Hpricot and XPath , I explained how to do screen scraping by writing the code on irb (Interactive Ruby Shell) console. Instead of writing the script line by line on console we can create a Ruby script that can be executed which will make our task much easier. So, in this post you will find how to write a Ruby script, how to execute a Ruby script, also how to scrap and store the result in table.

Here I will be scraping all the links given on the left panel under "My Blogs" section on my website "http://www.kumarritesh.com/" with XPath and will store the result in table in db. To store the result in table, let us create the table first in MySql. I named the db as 'scraping_db' and table as 'scraps'. Here is the code to create the db and table

CREATE DATABASE /*!32312 IF NOT EXISTS*/`scraping_db` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `scraping_db`;

/*Table structure for table `scraps` */

DROP TABLE IF EXISTS `scraps`;

CREATE TABLE `scraps` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `links` varchar(255) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

Now, I created the script file named 'screen-scraper.rb' and wrote the following code:

require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'active_record'

ActiveRecord::Base.establish_connection(
    :adapter  => 'mysql',
    :host     => 'localhost',
    :username => 'root',
    :password => '',
    :database => 'scraping_db')

class Scrap < ActiveRecord::Base
  @url      = "http://www.kumarritesh.com"
  @response = ''
  open(@url, "User-Agent" => "Ruby/#{RUBY_VERSION}"  ) 
{ |f|
    @response = f.read
  }

  doc   = Hpricot(@response)
  links = (doc/"/html/body/div/div/div[2]/div[2]/div[3]/div/ul/li/a").innerHTML
  puts "#{links} "

  links.each do |link|
    scraplink = Scrap.new(:links => link)
    scraplink.save
    puts "#{link} "
  end
end

Browse to the folder where this script is saved. Execute the above code by command "ruby screen-scraper.rb"
It will print "Quality AssuranceSearch Engine OptimizationRuby on RailsBlog Links" twice on the console and will create one record with data in the links column as "Quality AssuranceSearch Engine OptimizationRuby on RailsBlog Links".

So, now you know how to write a Ruby script, how to execute a Ruby script, also how to scrap and store the result in table.

Thursday, May 5, 2011

Routing error when running Rails 3 application server in production mode

I was developing a Rails3 application and I wanted to execute a bunch of JavaScript code only on production server. So, in order to do that in my view I added these lines:

<%- if RAILS_ENV == "production" -%>
      -- my JavaScript code --
<% end %>

Now, I wanted to test the code before deploying it on production. So, I needed to start the Rails server in production mode. To start a Rails3 application server in production mode, I passed '-e production' parameter as:
rails s -e production

But when I started browsing the application, all the stylesheets, images were gone and was getting Routing errors similar to the one given below:
Started GET "/javascripts/jquery.js?1303373839" for 127.0.0.1 at Thu May 05 19:55:09 +0530 2011

ActionController::RoutingError (No route matches "/javascripts/jquery.js"):

Reason was - Rails defaults not serve static assets in production, so to fix Routing Errors, I changed

config.serve_static_assets = false
line in 'config/environments/production.rb' to
config.serve_static_assets = true

And restarted the server in production mode. It solved the Routing issue.