Friday, July 29, 2011

Difference between Application server and Web Server

apache, nginx, IIS are web servers
mongrel, webrick, phusion passenger are app servers

App server is something which works with particular programming language and parses and executes the code
since mongrel and webrick can only work with rails, so they are app servers

Web servers are servers which can take the request from the browser.
Web servers normally works on port 80 though we can change the port in configuration
since mongrel and webrick can take that request directly, so they can be thought of as web servers but web servers do have a lot of other functionality like request pipeline, load balancing etc.
App servers lack these functionalities.

About Mongrel server:
mongrel work as web as well as app server if you are talking about dev environment
but in production, mongrel alone can not work it will be too slow
so we need a web server in front of mongrel

Thanks to Mr. Sumit  Garg & Mr. Sidhant for clarifying these points in details.
I would love to have others view also on this.

Difference between Validations, Callbacks and Observers

Validations allow you to ensure that only valid data is stored in your database.
Example: validates_presence_of :user_name, :password
                 validates_numericality_of :value

We can write custom validation also as

def validate
  errors.add(:price, “should be a positive value”) if price.nil?|| price < 0.01
end

Callbacks and observers allow you to trigger logic before or after an alteration of an object’s state.

Callbacks are methods that get called at certain moments of an object’s life cycle. With callbacks it’s possible to write code that will run whenever an Active Record object is created, saved, updated, deleted, validated, or loaded from the database.

Callbacks are hooks into the life cycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state. This can be used to make sure that associated and dependent objects are deleted when destroy is called (by overwriting before_destroy) or to massage attributes before they’re validated (by overwriting before_validation)

Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn’t directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a User model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn’t directly related to your model, you may want to consider creating an observer instead.

Getting error "undefined method `debug_rjs=' for ActionView::Base:Class (NoMethodError)"

Successfully installed RVM, Ruby 1.9.2 with RVM, Rails 3.2.0.beta
While upgrading to Rails 3.2.0.beta on Mac, getting following error:

/Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/thinking-sphinx-ea7673a0188f/lib/thinking_sphinx/search.rb:623: warning: encoding option is ignored - u
=> Booting WEBrick
=> Rails 3.2.0.beta application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_view/railtie.rb:34:in `block (3 levels) in <class:Railtie>': undefined method `debug_rjs=' for ActionView::Base:Class (NoMethodError)
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_view/railtie.rb:33:in `each'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_view/railtie.rb:33:in `block (2 levels) in <class:Railtie>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_view/railtie.rb:32:in `block in <class:Railtie>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:25:in `run'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:49:in `each'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/application.rb:92:in `initialize!'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ror/projects/restaurant/config/environment.rb:6:in `<top (required)>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `block in require'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `block in load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:616:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require'
    from /Users/ror/projects/restaurant/config.ru:4:in `block in <main>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:51:in `initialize'
    from /Users/ror/projects/restaurant/config.ru:1:in `new'
    from /Users/ror/projects/restaurant/config.ru:1:in `<main>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:40:in `eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:40:in `parse_file'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:200:in `app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands/server.rb:46:in `app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:252:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands/server.rb:70:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:54:in `block in <top (required)>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:49:in `tap'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:49:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Solution to fix the problem:
Comment the line in config/environments/development.rb  (if working on development)
# config.action_view.debug_rjs             = true

Getting error "Library not loaded: libmysqlclient.18.dylib (LoadError)" on Mac

On Mac, successfully installed RVM, ruby 1.9.2, mysql2 gem, Rails 3.1.0.rc5.
On starting rails server or rails console, getting following errors:

:restaurant ror$ rails c
/Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require': dlopen(/Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2/mysql2.bundle
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `block in require'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `block in load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:616:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:222:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/activesupport/lib/active_support/dependencies.rb:236:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.3.6/lib/mysql2.rb:9:in `<top (required)>'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `require'
    from /Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler.rb:120:in `require'
    from /Users/ror/projects/restaurant/config/application.rb:7:in `<top (required)>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:38:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:38:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

  Solution to fix the problem:
Type following command and then run Rails server or console:

-:restaurant ror$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

Another way is to create a soft link by command -
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Getting error "`method_missing': undefined method `named_scope' for # (NoMethodError)"

In my application, I am using Clicksteam plugin. While upgrading to Rails 3.1.0.rc5, getting following error:

 /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activerecord-3.1.0.rc5/lib/active_record/base.rb:1095:in `method_missing': undefined method `named_scope' for #<Class:0x3668480> (NoMethodError)
    from /Users/ror/projects/restaurant/vendor/plugins/clickstream/lib/app/models/stream.rb:8
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/vendor/plugins/clickstream/lib/clickstream.rb:3
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/vendor/plugins/clickstream/rails/init.rb:1
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/vendor/plugins/clickstream/init.rb:2
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/plugin.rb:80
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:25:in `run'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:50:in `run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `each'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/application.rb:92:in `initialize!'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `send'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/railties-3.1.0.rc5/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ror/projects/restaurant/config/environment.rb:6
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:639:in `new_constants_in'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/activesupport-3.1.0.rc5/lib/active_support/dependencies.rb:237:in `require'
    from /Users/ror/projects/restaurant/config.ru:4
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/rack-1.3.2/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.8/gems/rack-1.3.2/lib/rack/builder.rb:51:in `initialize'
    from /Users/ror/projects/restaurant/config.ru:1:in `new'
    from /Users/ror/projects/restaurant/config.ru:1 

 Solution to fix the problem:
Change 'named_scope' to 'scope' in line no - 8 in
vendor/plugins/clickstream/lib/app/models/steam.rb

Getting error "Error running 'make ', please read /Users/ror/.rvm/log/ruby-1.8.7-p352/make.log"

Installed rvm, ruby 1.9.2 through rvm successfully on Mac.
But while installing ruby-1.8.7-p352 through rvm, gives following error:

-:restaurant ror$ rvm 1.8.7
WARN: ruby ruby-1.8.7-p352 is not installed.
To install do: 'rvm install ruby-1.8.7-p352'
-:restaurant ror$ rvm install ruby-1.8.7-p352
Installing Ruby from source to: /Users/ror/.rvm/rubies/ruby-1.8.7-p352, this may take a while depending on your cpu(s)...

ruby-1.8.7-p352 - #fetching
ruby-1.8.7-p352 - #extracted to /Users/ror/.rvm/src/ruby-1.8.7-p352 (already extracted)
ruby-1.8.7-p352 - #configuring
ruby-1.8.7-p352 - #compiling
ERROR: Error running 'make ', please read /Users/ror/.rvm/log/ruby-1.8.7-p352/make.log
ERROR: There has been an error while running make. Halting the installation.


Solution to fix the problem:

Try following command:
- rvm get head;
- rvm reload;
- rvm remove 1.8.7;
- rvm install 1.8.7

Change RAILS_ROOT to Rails.root when upgrading to Rails 3

Getting following error while upgrading to Rails 3.1.0.rc5

NameError (uninitialized constant Search::RAILS_ROOT):
  app/models/search.rb:159:in `run'
  app/controllers/searches_controller.rb:66:in `new'

  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
  Rendered highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/actionpack/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (35.6ms)

Solution to fix the problem:

Change RAILS_ROOT to Rails.root

Getting error "`const_missing': uninitialized constant ActiveRecord::Associations::AssociationCollection (NameError)"

-:restaurant ror$ rails s
/Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/thinking-sphinx-ea7673a0188f/lib/thinking_sphinx/search.rb:623: warning: encoding option is ignored - u
=> Booting WEBrick
=> Rails 3.2.0.beta application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in `const_missing': uninitialized constant ActiveRecord::Associations::AssociationCollection (NameError)
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/will_paginate-3.0.pre2/lib/will_paginate/finders/active_record.rb:36:in `enable!'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/will_paginate-3.0.pre2/lib/will_paginate/railtie.rb:9:in `block in <class:Railtie>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:25:in `run'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:49:in `each'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/application.rb:92:in `initialize!'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/ror/projects/restaurant/config/environment.rb:6:in `<top (required)>'
    from /Users/ror/projects/restaurant/config.ru:4:in `block in <main>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:51:in `initialize'
    from /Users/ror/projects/restaurant/config.ru:1:in `new'
    from /Users/ror/projects/restaurant/config.ru:1:in `<main>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:40:in `eval'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/builder.rb:40:in `parse_file'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:200:in `app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands/server.rb:46:in `app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/rack-1.3.2/lib/rack/server.rb:252:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands/server.rb:70:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:54:in `block in <top (required)>'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:49:in `tap'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/bundler/gems/rails-30dae273c85a/railties/lib/rails/commands.rb:49:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Solution to fix the problem:

In my gemfile, I was using "will_paginate-3.0.pre2"

Fixed by changing will paginate version to pre4
gem 'will_paginate', '3.0.pre4'

Sunday, July 24, 2011

Getting error "ThinkingSphinx::SphinxError (unknown local index '' in search request):"


We define index for Sphinx in model in blocks as such:
define_index do
      indexes :name, :sortable => true
      indexes description
...
...
    end

Whenever we do some changes in such type of index and start ThinkingSphinx it gives us error as :
ThinkingSphinx::SphinxError (unknown local index '<delta_name>' in search request):

To solve such type of issues, run
rake ts:rebuild
It will first do changes in config file and then will do indexing as per the changes done, then you will be able to run Thinking Sphinx.

Wednesday, July 6, 2011

searchd giving error "dyld: Library not loaded: libmysqlclient.18.dylib" on Mac

On Mac system, in one of my application using Thinking Sphinx. After installation while running searchd, it gives following errors:

$ searchd
dyld: Library not loaded: libmysqlclient.18.dylib
  Referenced from: /usr/local/bin/searchd
  Reason: image not found
Trace/BPT trap
-:sphinx-0.9.8 ror$ cd ..
-:Downloads ror$ l
-bash: l: command not found

Solution:
It's because unable to find the libmysqlclient library. Add the following to to your ~/.profile:

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
and it will work fine